<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: An introduction to code blocks</title>
	<atom:link href="http://www.rubyfleebie.com/an-introduction-to-code-blocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/</link>
	<description>Because programming should be fun</description>
	<lastBuildDate>Wed, 04 Jan 2012 05:17:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ruby Rocks -- à la Francois Montagne &#124; Montreal Tech Watch</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-341</link>
		<dc:creator>Ruby Rocks -- à la Francois Montagne &#124; Montreal Tech Watch</dc:creator>
		<pubDate>Mon, 13 Aug 2007 18:49:15 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-341</guid>
		<description>[...] 3 times. Instead, you just have to use a Ruby key concept called &#8220;code blocks&#8221; (have a look at this post if you want to know more about code blocks). Secondly, do you see where is the conditional operation? Yep! at the end of the [...]</description>
		<content:encoded><![CDATA[<p>[...] 3 times. Instead, you just have to use a Ruby key concept called &#8220;code blocks&#8221; (have a look at this post if you want to know more about code blocks). Secondly, do you see where is the conditional operation? Yep! at the end of the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-18</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Fri, 23 Mar 2007 22:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-18</guid>
		<description>That is assuming we wanted to provide a pure ruby implementation of the idea that the times method is based on and not depend on anything defined in the superclass.</description>
		<content:encoded><![CDATA[<p>That is assuming we wanted to provide a pure ruby implementation of the idea that the times method is based on and not depend on anything defined in the superclass.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Cooper</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-17</link>
		<dc:creator>Peter Cooper</dc:creator>
		<pubDate>Fri, 23 Mar 2007 22:14:51 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-17</guid>
		<description>How&#039;s that cleaner than self.times do ... end  ?</description>
		<content:encoded><![CDATA[<p>How&#8217;s that cleaner than self.times do &#8230; end  ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-13</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Fri, 23 Mar 2007 14:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-13</guid>
		<description>The code for the Integer#times implementation could be a bit cleaner. To match how the real Integer class behaves, you&#039;d do something like:
class Integer
  def times
    # we can give for loops a Range to make it a bit cleaner
    for i in 0...self
      # just like the default times implementation we yield the current index
      # your block doesn&#039;t have to handle this so this will work for 
      # blocks with any number of arguments
      yield i
    end
    # the default implementation returns a reference to itself after it&#039;s done
    self
  end
end</description>
		<content:encoded><![CDATA[<p>The code for the Integer#times implementation could be a bit cleaner. To match how the real Integer class behaves, you&#8217;d do something like:<br />
class Integer<br />
  def times<br />
    # we can give for loops a Range to make it a bit cleaner<br />
    for i in 0&#8230;self<br />
      # just like the default times implementation we yield the current index<br />
      # your block doesn&#8217;t have to handle this so this will work for<br />
      # blocks with any number of arguments<br />
      yield i<br />
    end<br />
    # the default implementation returns a reference to itself after it&#8217;s done<br />
    self<br />
  end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Cooper</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-10</link>
		<dc:creator>Peter Cooper</dc:creator>
		<pubDate>Thu, 22 Mar 2007 16:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-10</guid>
		<description>I must confess I haven&#039;t really read much of this, I just wanted to throw out an inspiration in case he was stuck :)

I guess generally in these situations you would use a collection. At least, that&#039;s how Rails does it. find(:all).each do.. end.. etc. :)</description>
		<content:encoded><![CDATA[<p>I must confess I haven&#8217;t really read much of this, I just wanted to throw out an inspiration in case he was stuck :)</p>
<p>I guess generally in these situations you would use a collection. At least, that&#8217;s how Rails does it. find(:all).each do.. end.. etc. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-7</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Thu, 22 Mar 2007 10:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-7</guid>
		<description>I think Peter understood the question better than me. He&#039;s right. By using a hash, the order of the various parameters doesn&#039;t matter anymore.</description>
		<content:encoded><![CDATA[<p>I think Peter understood the question better than me. He&#8217;s right. By using a hash, the order of the various parameters doesn&#8217;t matter anymore.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Cooper</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-6</link>
		<dc:creator>Peter Cooper</dc:creator>
		<pubDate>Thu, 22 Mar 2007 04:22:01 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-6</guid>
		<description>Dan:

def list_users(params)
  ..
  yield params
  ..
end

list_users( :name =&gt; name, :password =&gt; password, :userid =&gt; id ) do &#124;user&#124;
 .. whatever ..  user[:name] etc.
end</description>
		<content:encoded><![CDATA[<p>Dan:</p>
<p>def list_users(params)<br />
  ..<br />
  yield params<br />
  ..<br />
end</p>
<p>list_users( :name =&gt; name, :password =&gt; password, :userid =&gt; id ) do |user|<br />
 .. whatever ..  user[:name] etc.<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-4</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Wed, 21 Mar 2007 16:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-4</guid>
		<description>Dan, you have to know in advance what are the &quot;requirements&quot; for that method. For example, the Array class exposes a method named &quot;each&quot; that loop through every elements of an array instance. At every passages in the loop, the each method will yield the current item in the collection. You have to know in advance this fact to use the each method properly. I hope it does answer your question.

To everyone else, click on Dan&#039;s link to do some remarkable javascript katas!</description>
		<content:encoded><![CDATA[<p>Dan, you have to know in advance what are the &#8220;requirements&#8221; for that method. For example, the Array class exposes a method named &#8220;each&#8221; that loop through every elements of an array instance. At every passages in the loop, the each method will yield the current item in the collection. You have to know in advance this fact to use the each method properly. I hope it does answer your question.</p>
<p>To everyone else, click on Dan&#8217;s link to do some remarkable javascript katas!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/comment-page-1/#comment-3</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 21 Mar 2007 16:06:40 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=4#comment-3</guid>
		<description>Question : how do I know the parameters passed by the yield() in a class that I do not see the source code?

I mean, I have  yield(name, password, userid) in a list_users() function of a User class that I do not own the code?

When I call it, how can I know that the parameters are name, password, userid in that order?</description>
		<content:encoded><![CDATA[<p>Question : how do I know the parameters passed by the yield() in a class that I do not see the source code?</p>
<p>I mean, I have  yield(name, password, userid) in a list_users() function of a User class that I do not own the code?</p>
<p>When I call it, how can I know that the parameters are name, password, userid in that order?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

