<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Ruby - Cognizant Transmutation</title>
	<atom:link href="https://www.ibd.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.ibd.com</link>
	<description>Internet Bandwidth Development: Composting the Internet for over Two Decades</description>
	<lastBuildDate>Sun, 19 Feb 2012 07:19:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1</generator>

<image>
	<url>https://i0.wp.com/www.ibd.com/wp-content/uploads/2019/01/fullsizeoutput_7ae8.jpeg?fit=32%2C32&#038;ssl=1</url>
	<title>Ruby - Cognizant Transmutation</title>
	<link>https://www.ibd.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/><site xmlns="com-wordpress:feed-additions:1">156814061</site>	<item>
		<title>Avoiding a series of tests with Ruby Hashes of Hashes that might have nil before the leaf hash</title>
		<link>https://www.ibd.com/ruby-rails/avoiding-a-series-of-tests-with-hashes-of-hashes-that-might-have-nil-before-the-leaf-hash/</link>
		
		<dc:creator><![CDATA[Robert J Berger]]></dc:creator>
		<pubDate>Thu, 04 Aug 2011 05:41:11 +0000</pubDate>
				<category><![CDATA[Opscode Chef]]></category>
		<category><![CDATA[Ruby / Rails]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Chef]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">http://blog2.ibd.com/?p=805</guid>

					<description><![CDATA[<p>I&#8217;m mostly using Ruby to write Opscode Chef Cookbooks. There are a lot of hashes of hashes that contain attributes or Data Bags. Things that look like: If I wanted to test if this value is set I couldn&#8217;t safely just say: because in some cases or may be nil . If ether of those were nil and I execute&#8230;</p>
<p>The post <a href="https://www.ibd.com/ruby-rails/avoiding-a-series-of-tests-with-hashes-of-hashes-that-might-have-nil-before-the-leaf-hash/">Avoiding a series of tests with Ruby Hashes of Hashes that might have nil before the leaf hash</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m mostly using Ruby to write <a href="http://www.opscode.com/" target="_blank">Opscode </a>Chef <a href="http://wiki.opscode.com/display/chef/Cookbooks" target="_blank">Cookbooks</a>. There are a lot of hashes of hashes that contain <a href="http://wiki.opscode.com/display/chef/Attributes" target="_blank">attributes</a> or <a href="http://wiki.opscode.com/display/chef/Data+Bags" target="_blank">Data Bags</a>. Things that look like:</p>
<pre class="brush: ruby; title: ; notranslate">app['rds_database'][environment]['rds_name']</pre>
<p>If I wanted to test if this value is set I couldn&#8217;t safely just say:</p>
<pre class="brush: ruby; title: ; notranslate">if app['rds_database'][environment]['rds_name']</pre>
<p>because in some cases</p>
<pre class="brush: ruby; title: ; notranslate">if app['rds_database']</pre>
<p>or</p>
<pre class="brush: ruby; title: ; notranslate">if app['rds_database'][environment]</pre>
<p>may be nil .</p>
<p>If ether of those were nil and I execute</p>
<pre class="brush: ruby; title: ; notranslate">if app['rds_database'][environment]['rds_name']</pre>
<p>I would get an exception like:</p>
<pre class="brush: plain; title: ; notranslate">NoMethodError: undefined method `[]' for nil:NilClass</pre>
<p>I have been doing something like:</p>
<pre class="brush: ruby; title: ; notranslate">if app['rds_database'] &amp;&amp; app['rds_database'][environment] &amp;&amp; app['rds_database'][environment]['rds_name']</pre>
<p>But that was starting to make me sick to my stomach. I like my Ruby fine and DRY</p>
<p>So I scoured the Internet (well googled a bit) and found a couple of good Stack Overflow posts like <a href="http://stackoverflow.com/questions/6334639/how-to-access-an-element-deep-in-an-array-of-arrays-without-getting-undefined-me" target="_blank">How to access an element deep in an array of arrays without getting &#8216;undefined method&#8217; error</a> and <a href="http://stackoverflow.com/questions/4371716/looking-for-a-good-way-to-avoid-hash-conditionals-in-ruby" target="_blank">Looking for a Good Way to Avoid Hash Conditionals in Ruby</a>.</p>
<p>But most of them were ways to Monkey Patch the Hash Object or use new operators that are loaded by Gems.</p>
<p>One of them was pretty simple and was pretty DRY. Though some commentors called it <em>an indiscriminate use of </em> <code>rescue</code> <em>and EEEEVVVVIIILLLLL.</em></p>
<p>But it seems to me to be a very discriminate use of rescue, as any case where the rescue happens, I want it to return nil:</p>
<pre class="brush: ruby; title: ; notranslate">if (app['rds_database'][environment]['rds_name'] rescue nil)</pre>
<p>The parenthesis aren&#8217;t needed, but I think it makes it clearer whats going on. Especially if you say something like:</p>
<pre class="brush: ruby; title: ; notranslate">return unless (app['rds_database'][environment]['rds_name'] rescue nil)</pre>
<p>So I&#8217;m going to give that a try for a while.</p><p>The post <a href="https://www.ibd.com/ruby-rails/avoiding-a-series-of-tests-with-hashes-of-hashes-that-might-have-nil-before-the-leaf-hash/">Avoiding a series of tests with Ruby Hashes of Hashes that might have nil before the leaf hash</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">805</post-id>	</item>
		<item>
		<title>Nice jruby installation cookbook (Opscode)</title>
		<link>https://www.ibd.com/sysadmin/nice-jruby-installation-cookbook-opscode/</link>
					<comments>https://www.ibd.com/sysadmin/nice-jruby-installation-cookbook-opscode/#comments</comments>
		
		<dc:creator><![CDATA[Robert J Berger]]></dc:creator>
		<pubDate>Tue, 09 Mar 2010 03:04:01 +0000</pubDate>
				<category><![CDATA[Opscode Chef]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">http://blog2.ibd.com/?p=546</guid>

					<description><![CDATA[<p>There are a lot of good example Opscode cookbooks out there. Unfortunately they can be hard to find. People are not submitting them to the Opscode Cookbook repository. Its still hard to untangle your own cookbooks into something that can be put in a sharable format I guess. Right now, the most productive way to find cookbooks seems to be&#8230;</p>
<p>The post <a href="https://www.ibd.com/sysadmin/nice-jruby-installation-cookbook-opscode/">Nice jruby installation cookbook (Opscode)</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>There are a lot of good example Opscode cookbooks out there. Unfortunately they can be hard to find. People are not submitting them to the Opscode Cookbook repository. Its still hard to untangle your own cookbooks into something that can be put in a sharable format I guess.</p>
<p>Right now, the most productive way to find cookbooks seems to be to search github. I always do a search before I write my own. Google searches are tough since &#8220;chef&#8221;, &#8220;cookbooks&#8221; are overloaded from the &#8220;real cooking&#8221; domain. And if you put in some package name, you tend to get announcements about the package and a mention about Opscode, but rarely about an Opscode Cookbook for that package.</p>
<p>Today I discovered that I needed a cookbook to install jruby. So after a useless Google Search. I did a search &#8220;jruby cookbook&#8221; on github and soon found Theo Cushion&#8217;s cookbook clone with a jruby addition.</p>
<p><strong>Update 2/18/2012:</strong></p>
<p>Looks like Theo Cushion&#8217;s github account no longer exists. Another jruby cookbook can be found Jorge Falcão at https://github.com/jlbfalcao/chef-jruby</p>
<p>Its better to not have to write it yourself! My thanks to Theo, Jorge  and the many others who share their code.</p>
<p><strong><br />
</strong></p><p>The post <a href="https://www.ibd.com/sysadmin/nice-jruby-installation-cookbook-opscode/">Nice jruby installation cookbook (Opscode)</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.ibd.com/sysadmin/nice-jruby-installation-cookbook-opscode/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">546</post-id>	</item>
		<item>
		<title>Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</title>
		<link>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/</link>
					<comments>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/#comments</comments>
		
		<dc:creator><![CDATA[Robert J Berger]]></dc:creator>
		<pubDate>Fri, 16 Jan 2009 07:32:10 +0000</pubDate>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Ruby / Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[monkey patch]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">http://blog2.ibd.com/?p=156</guid>

					<description><![CDATA[<p>Flinn Mueller aka actsasflinn wrote an blog post Cross domain RESTful JSON-P with Rails back in July. There he showed how to monkeypatch Rails to allow json-p to do all the REST verbs even when going across domains. He also showed how to make the json-p calls with jquery. A very nice solution that we take advantage of in one&#8230;</p>
<p>The post <a href="https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/">Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><a href="http://www.actsasflinn.com" target="_blank">Flinn Mueller aka actsasflinn</a> wrote an blog post <a href="http://www.actsasflinn.com/2008/06/13/cross-domain-restful-json-p-with-rails" target="_blank">Cross domain RESTful JSON-P with Rails</a> back in July. There he showed how to monkeypatch Rails to allow json-p to do all the REST verbs even when going across domains. He also showed how to make the json-p calls with jquery. A very nice solution that we take advantage of in one of our apps. The only problem we had was that it stopped working when we upgraded to Rails 2.2.2.</p>
<p>There are other issues using this technique. To quote Flinn:</p>
<blockquote><p>Achtung! Monkey patching with the above will expose your create method without using an actual post. Imho no big deal, others might be more cautious (<a href="http://actsasflinn.com/articles/2008/04/27/captcha-sucks">CAPTCHA</a>is always an option), ymmv.</p></blockquote>
<p>See his original article for details on how to use it generally. </p>
<p>The problem with the monkeypatch that he wrote up is that Rails 2.2.2 changed the function that was monkeypatched so the patch stopped working. Below is code that will work on both pre and post 2.2.2 Rails:</p>
<pre>
<pre>
<span>module</span> ActionController
<span>  class</span> AbstractRequest

<span>    </span><span>def</span> request_method

<span>      if</span> Rails::VERSION::STRING &lt;<span> "2.2.2"</span>

<span>        <span>@request_method</span><span> ||=</span><span> begin</span></span>

<span>          method = (parameters[<span>:_method</span>].blank? ?<span> </span><span>@env</span>[<span>'REQUEST_METHOD'</span>] : parameters[<span>:_method</span>].to_s).<span>downcase</span></span>

<span><span>          if</span> ACCEPTED_HTTP_METHODS.include?(method)</span>

            method.to_sym

          else

            raise UnknownHttpMethod,<span> "#{</span>method<span>}, accepted HTTP methods are #{</span>ACCEPTED_HTTP_METHODS.to_a.to_sentence<span>}"</span>

<span>          end</span>

        end

      else

        method =<span> </span><span>@env</span>[<span>'REQUEST_METHOD'</span>]

        method = parameters[<span>:_method</span>]<span> unless</span> parameters[<span>:_method</span>].blank?

        HTTP_METHOD_LOOKUP[method] || raise(UnknownHttpMethod,<span> "#{</span>method<span>}, accepted HTTP methods are #{</span>HTTP_METHODS.to_sentence<span>}"</span>)
      end

    end

  end
end</pre><p>The post <a href="https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/">Cross Domain RESTful AJAX with jQuery and Rails 2.2.2</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.ibd.com/howto/cross-domain-restful-ajax-with-jquery-and-rails-222/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">156</post-id>	</item>
		<item>
		<title>QuarkRuby: Consume non rails-style REST APIs</title>
		<link>https://www.ibd.com/ruby-rails/quarkruby-consume-non-rails-style-rest-apis/</link>
		
		<dc:creator><![CDATA[Robert J Berger]]></dc:creator>
		<pubDate>Wed, 31 Dec 2008 01:09:41 +0000</pubDate>
				<category><![CDATA[Ruby / Rails]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">http://blog2.ibd.com/?p=87</guid>

					<description><![CDATA[<p>It seems that most &#8220;RESTful&#8221; APIs in the wild are well, pretty wild. They don&#8217;t meet the strict requirements of the pure CRUD/REST of ActiveResource. The article in QuarkRuby:  Consume non rails-style REST APIs shows how to create a nice ruby wrapper around ActiveResource so you can adapt to any arbitrary REST / http interface on the Internet.</p>
<p>The post <a href="https://www.ibd.com/ruby-rails/quarkruby-consume-non-rails-style-rest-apis/">QuarkRuby: Consume non rails-style REST APIs</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>It seems that most &#8220;RESTful&#8221; APIs in the wild are well, pretty wild. They don&#8217;t meet the strict requirements of the pure CRUD/REST of ActiveResource.</p>
<p>The article in <a href="http://www.quarkruby.com">QuarkRuby</a>:  <a href="http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis">Consume non rails-style REST APIs</a> shows how to create a nice ruby wrapper around ActiveResource so you can adapt to any arbitrary REST / http interface on the Internet.</p><p>The post <a href="https://www.ibd.com/ruby-rails/quarkruby-consume-non-rails-style-rest-apis/">QuarkRuby: Consume non rails-style REST APIs</a> first appeared on <a href="https://www.ibd.com">Cognizant Transmutation</a>.</p>]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">87</post-id>	</item>
	</channel>
</rss>
