<?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/"
	>

<channel>
	<title>Dare to Dream? &#187; Ruby</title>
	<atom:link href="http://www.makuchaku.in/blog/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://www.makuchaku.in/blog</link>
	<description>Good judgment comes from experience; Experience comes from bad judgment.</description>
	<lastBuildDate>Sun, 02 Oct 2011 19:29:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Block magic for Rails helpers</title>
		<link>http://www.makuchaku.in/blog/block-magic-for-rails-helpers</link>
		<comments>http://www.makuchaku.in/blog/block-magic-for-rails-helpers#comments</comments>
		<pubDate>Wed, 13 Oct 2010 20:48:03 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[for-adomado]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=988</guid>
		<description><![CDATA[Ever wondered how can you have something like this &#60;% some_helper do %&#62; Some text here &#60;% end %&#62; Well, here how it is&#8230; def some_helper(&#038;block) content = capture(&#038;block) concat("this comes before the block", block.binding) concat(content, block.binding) # adds "Some text here" to the view concat("this comes after the block", block.binding) end Neat! Isn&#8217;t it [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/block-magic-for-rails-helpers&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p>Ever wondered how can you have something like this</p>
<blockquote>
<pre>&lt;% some_helper do %&gt;
  Some text here
&lt;% end %&gt;</pre>
</blockquote>
<p>Well, here how it is&#8230;</p>
<blockquote>
<pre>
def some_helper(&#038;block)
    content = capture(&#038;block)
    concat("this comes before the block", block.binding)
    concat(content, block.binding) # adds "Some text here" to the view
    concat("this comes after the block", block.binding)
end
</pre>
</blockquote>
<p>Neat! Isn&#8217;t it <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/block-magic-for-rails-helpers&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/block-magic-for-rails-helpers/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Will be introducing MAIT students to Ruby &amp; Rails&#8230;</title>
		<link>http://www.makuchaku.in/blog/will-be-introducing-mait-students-to-ruby-rails</link>
		<comments>http://www.makuchaku.in/blog/will-be-introducing-mait-students-to-ruby-rails#comments</comments>
		<pubDate>Mon, 30 Aug 2010 17:53:26 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Workshop]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=966</guid>
		<description><![CDATA[Now this is going to be fun! Workshop for MAIT students (part 1 of 2) No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/will-be-introducing-mait-students-to-ruby-rails&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p style="text-align: left;">Now this is going to be fun!</p>
<div class="mceTemp mceIEcenter" style="text-align: left;">
<dl id="attachment_967" class="wp-caption aligncenter" style="width: 657px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-967" title="Workshop - 1 (Ruby)" src="http://www.makuchaku.in/blog/wp-content/uploads/2010/08/Screenshot-1.png" alt="Workshop - 1 (Ruby)" width="647" height="484" /></dt>
<dd class="wp-caption-dd" style="text-align: left;">Workshop for MAIT students (part 1 of 2)</dd>
</dl>
</div>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/will-be-introducing-mait-students-to-ruby-rails&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/will-be-introducing-mait-students-to-ruby-rails/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Super sexy BDD with Cucumber and Webrat</title>
		<link>http://www.makuchaku.in/blog/super-sexy-bdd-with-cucumber-and-webrat</link>
		<comments>http://www.makuchaku.in/blog/super-sexy-bdd-with-cucumber-and-webrat#comments</comments>
		<pubDate>Mon, 15 Mar 2010 07:11:04 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[AdoMado]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=871</guid>
		<description><![CDATA[Fatal &#8211; you don&#8217;t have any automated test cases Recoverable &#8211; you have some sorts of test suite in place Best &#8211; you are already using unit/integration tests or have TDD/RSpec in place Without wasting words, I&#8217;d put you right to the Cucumber and Webrat goodness&#8230; Points worth noting&#8230; This was ALL the code I [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/super-sexy-bdd-with-cucumber-and-webrat&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p>Fatal &#8211; you don&#8217;t have any automated test cases<br />
Recoverable &#8211; you have some sorts of test suite in place<br />
Best &#8211; you are already using unit/integration tests or have TDD/RSpec in place <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Without wasting words, I&#8217;d put you right to the <a href="http://cukes.info/" target="_blank">Cucumber</a> and <a href="http://github.com/brynary/webrat" target="_blank">Webrat</a> goodness&#8230;</p>
<p><a href="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_0021.png"><img class="size-full wp-image-873 alignnone" title="Scenarios" src="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_0021.png" alt="" width="371" height="248" /></a></p>
<p><a href="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_003.png"><img class="alignnone size-full wp-image-874" title="Steps" src="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_003.png" alt="" width="779" height="246" /></a></p>
<p><a href="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_004.png"><img class="alignnone size-full wp-image-875" title="Test result" src="http://www.makuchaku.in/blog/wp-content/uploads/2010/03/screenshot_004.png" alt="" width="531" height="237" /></a></p>
<p>Points worth noting&#8230;</p>
<ul>
<li>This was ALL the code I wrote to test the login scenario</li>
<li>The webrat helper (generated by Cucumber) did most of the work (steps 2, 4, 5) &#8211; out of the box!</li>
</ul>
<p>An <a href="http://www.teachmetocode.com/screencasts/introduction-to-outside-in-development-with-cucumber" target="_blank">excellent screencast</a> you should see if you are interested in BDD for your Rails app with Cucumber and Webrat</p>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/super-sexy-bdd-with-cucumber-and-webrat&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/super-sexy-bdd-with-cucumber-and-webrat/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning from the best!</title>
		<link>http://www.makuchaku.in/blog/learning-from-the-best</link>
		<comments>http://www.makuchaku.in/blog/learning-from-the-best#comments</comments>
		<pubDate>Fri, 12 Feb 2010 04:58:47 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=830</guid>
		<description><![CDATA[Just bought &#8220;Programming Ruby 1.9&#8221; from Flipkart. From For Blog When I joined IBM ISS UI team and my tech lead suggested that we should start doing things in Rails- and I was prompt enough to pop up a suggestion &#8211; &#8220;that why don&#8217;t we use Python based web app frameworks Django or Turbo Gears [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/learning-from-the-best&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p>Just bought &#8220;<a href="http://www.pragprog.com/titles/ruby3/programming-ruby-1-9" target="_blank">Programming Ruby 1.9</a>&#8221; from <a href="http://www.flipkart.com/programming-ruby-dave-thomas-chad/1934356085-o2x3fjgnvc" target="_blank">Flipkart</a>.</p>
<table style="width: auto;">
<tbody>
<tr>
<td><a href="http://picasaweb.google.com/lh/photo/RThH0Xbmw7BjgWz0a62Iag?feat=embedwebsite"><img src="http://lh6.ggpht.com/_RWv_ppZ2Nxo/S3TcGzgiP8I/AAAAAAAAAXY/M7thSJxGPC4/s400/ruby_book.jpg" alt="" /></a></td>
</tr>
<tr>
<td style="font-family: arial,sans-serif; font-size: 11px; text-align: right;">From <a href="http://picasaweb.google.com/makuchaku.in/ForBlog?feat=embedwebsite">For Blog</a></td>
</tr>
</tbody>
</table>
<p>When I joined IBM ISS UI team and my tech lead suggested that we should start doing things in Rails- and I was prompt enough to pop up a suggestion &#8211; &#8220;that why don&#8217;t we use <a href="http://wiki.python.org/moin/WebFrameworks" target="_blank">Python based web app frameworks</a> Django or Turbo Gears (as I had some python experience)&#8221;.</p>
<p>All he replied was &#8211; &#8220;when we are looking for the best framework, why not use the one everyone&#8217;s trying to become&#8221;.</p>
<p>And hence, the awesome journey to Rails began.<br />
Understanding Ruby better will make it so much more fun.</p>
<p>PS: No disrespect meant to the awesome work being put in by the Python community. Python rocks! So does Ruby!</p>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/learning-from-the-best&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/learning-from-the-best/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Super easy SUB-URI hosting with mod_rails</title>
		<link>http://www.makuchaku.in/blog/super-easy-sub-uri-hosting-with-mod_rails</link>
		<comments>http://www.makuchaku.in/blog/super-easy-sub-uri-hosting-with-mod_rails#comments</comments>
		<pubDate>Thu, 27 Aug 2009 20:54:40 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[A strong urge to blog...]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Just for archive]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[AMI]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[mod_rails]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=729</guid>
		<description><![CDATA[With an Amazon EC2 instance up, next very obvious task was to get the hosting up. Objective was to host static content along with multiple Rails apps on the same EC2 instance. Purists might not agree to this, but getting up and running was the first target. Apache is configured with DocumentRoot as /mnt/app/shared My [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/super-easy-sub-uri-hosting-with-mod_rails&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p>With an Amazon EC2 instance up, next very obvious task was to get the hosting up. Objective was to host static content along with multiple Rails apps on the same EC2 instance. Purists might not agree to this, but getting up and running was the first target.</p>
<p>Apache is configured with DocumentRoot as /mnt/app/shared</p>
<p>My Rails apps live inside /mnt/app/releases/&lt;app_name&gt;/&lt;app_dir_structure&gt;</p>
<p>&lt;app_name_1&gt; should be exposed as http://blah-blah.com/dev</p>
<p>/etc/apache2/sites-available/ looks like</p>
<blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;VirtualHost *:80&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">DocumentRoot /mnt/app/shared</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">RailsBaseURI /dev</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/VirtualHost&gt;</div>
<blockquote><p>&lt;VirtualHost *:80&gt;</p></blockquote>
<blockquote><p>DocumentRoot /mnt/app/shared</p></blockquote>
<blockquote><p>RailsBaseURI /dev</p></blockquote>
<blockquote><p>&lt;/VirtualHost&gt;</p></blockquote>
</blockquote>
<p><span style="background-color: #ffffff;">(This is important)<br />
Inside the /mnt/app/shared directory, my /dev symlink now points to <span style="background-color: #ffffff;">/mnt/app/releases/&lt;app_name_1&gt;/public</span></span></p>
<p><span style="background-color: #ffffff;"><span style="background-color: #ffffff;">And inside my &lt;app_name_1&gt;/config/environment.rb, just before the Initializer block ends, add</span></span></p>
<p><span style="background-color: #ffffff;"><span style="background-color: #ffffff;"><span style="color: #333333; font-family: 'Helvetica Neue', helvetica, arial, sans-serif; line-height: 20px;"> </span></span></span></p>
<pre style="margin-top: 0.1em; margin-right: 0px; margin-bottom: 1.2em; margin-left: 0px; overflow-x: auto; overflow-y: auto; font-family: courier, monospace; padding: 0px;">config.action_controller.relative_url_root = "/dev"</pre>
<p><span style="background-color: #ffffff;">And you&#8217;r done! Touch the &lt;app_name_1&gt;/tmp/restart.txt file and reload your app in the browser! It should be running!</span></p>
<p><span style="background-color: #ffffff;">Some excellent material to read before attempting this&#8230;</span></p>
<ul>
<li><span style="background-color: #ffffff;"><a href="http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri" target="_blank">mod_rails documentation for Sub-URI deployments</a></span></li>
<li><span style="background-color: #ffffff;"><a href="http://collab.stat.ucla.edu/users/jose/weblog/9e335/A_Complete_Guide_to_Passenger_Sub_URI_Configuration.html" target="_blank">Jose&#8217;s blog on Sub-URI deployments</a></span></li>
</ul>
<p>Oh yeah, the AMI being used is <a href="http://www.webficient.com/2009/05/03/help-test-our-new-amazon-ec2-images" target="_blank">Webficient&#8217;s Ubuntu 8.04 image</a>, with Rails 2.3.2, passenger, etc etc.</p>
<p>Next target &#8211; move over the configuration to <a href="http://reductivelabs.com/trac/puppet/wiki/PuppetIntroduction" target="_blank">Puppet</a>!</p>
<p><span style="background-color: #ffffff;">Good Luck <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </span></p>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/super-easy-sub-uri-hosting-with-mod_rails&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/super-easy-sub-uri-hosting-with-mod_rails/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Revisting Ruby &#8211; Array.each</title>
		<link>http://www.makuchaku.in/blog/revisting-ruby-array-each</link>
		<comments>http://www.makuchaku.in/blog/revisting-ruby-array-each#comments</comments>
		<pubDate>Fri, 07 Aug 2009 04:56:46 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Array.each]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[Revisiting Ruby]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=722</guid>
		<description><![CDATA[I&#8217;ve been in love with Ruby for long now &#8211; and its only obvious that I should get serious about it. Hence, I&#8217;ve decided to go through Programming Ruby 1.9 &#8211; a chapter a day. Understanding Array.each and blocks #!/usr/bin/env ruby &#160; class MyObject &#160; attr_accessor :data &#160; &#160; def initialize &#160; &#160; @data = [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[ 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/revisting-ruby-array-each&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span><p>I&#8217;ve been in love with Ruby for long now &#8211; and its only obvious that I should get serious about it.</p>
<p>Hence, I&#8217;ve decided to go through <a href="http://www.pragprog.com/titles/ruby3/programming-ruby-1-9" target="_blank">Programming Ruby 1.9</a> &#8211; a chapter a day.</p>
<p><strong>Understanding Array.each and blocks</strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">#!/usr/bin/env ruby</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">class</span> MyObject</div>
</li>
<li class="li1">
<div class="de1">&nbsp; attr_accessor <span class="re3">:data</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">def</span> initialize</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">@data</span> = %w<span class="br0">&#123;</span>maku chaku was here<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw1">def</span> simple_yield_example</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">puts</span> <span class="st0">&quot;start&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">yield</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">yield</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">puts</span> <span class="st0">&quot;end&quot;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">def</span> each</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; idx = <span class="nu0">0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">while</span> idx &lt; <span class="re1">@data</span>.<span class="me1">length</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="kw1">yield</span> <span class="re1">@data</span><span class="br0">&#91;</span>idx<span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; idx += <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">puts</span> <span class="st0">&quot;##############&quot;</span></div>
</li>
<li class="li1">
<div class="de1">MyObject.<span class="me1">new</span>.<span class="me1">simple_yield_example</span> <span class="br0">&#123;</span> <span class="kw3">puts</span> <span class="st0">&quot;Hello there!&quot;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw3">puts</span> <span class="st0">&quot;##############&quot;</span></div>
</li>
<li class="li1">
<div class="de1">MyObject.<span class="me1">new</span>.<span class="me1">each</span> <span class="kw1">do</span> |val|</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">puts</span> val</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
</ol>
</div>
<p><strong><br />
Output</strong></p>
<blockquote><p>[makuchaku@Warrior ruby]$ ./each.rb<br />
##############<br />
start<br />
Hello there!<br />
Hello there!<br />
end<br />
##############<br />
maku<br />
chaku<br />
was<br />
here</p></blockquote>
<p><strong><br />
Explanation</strong></p>
<p>Objective was to implement a lookalike of &#8220;each&#8221; as as iterator. A code block, when associated with a method call can be called by the method by using &#8220;yield&#8221;. The number of variables being passed into each block should match the number of variables being passed into the yield.</p>
 
<span class = "" style = "height: 40px;  "><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.makuchaku.in/blog/revisting-ruby-array-each&layout=button_count&send=false&show_faces=false&width=100&action=like&colorscheme=light&font=" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:40px"></iframe></span>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/revisting-ruby-array-each/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

