<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: An introduction to code blocks</title>
	<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/</link>
	<description>Because programming should be fun</description>
	<pubDate>Mon, 08 Sep 2008 09:10:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: Dan</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-3</link>
		<author>Dan</author>
		<pubDate>Wed, 21 Mar 2007 16:06:40 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#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>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-4</link>
		<author>Frank</author>
		<pubDate>Wed, 21 Mar 2007 16:48:08 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-4</guid>
					<description>Dan, you have to know in advance what are the "requirements" for that method. For example, the Array class exposes a method named "each" 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'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: Peter Cooper</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-6</link>
		<author>Peter Cooper</author>
		<pubDate>Thu, 22 Mar 2007 04:22:01 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-6</guid>
					<description>Dan:

def list_users(params)
  ..
  yield params
  ..
end

list_users( :name =&#62; name, :password =&#62; password, :userid =&#62; 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-7</link>
		<author>Frank</author>
		<pubDate>Thu, 22 Mar 2007 10:57:05 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-7</guid>
					<description>I think Peter understood the question better than me. He's right. By using a hash, the order of the various parameters doesn'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-10</link>
		<author>Peter Cooper</author>
		<pubDate>Thu, 22 Mar 2007 16:22:46 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-10</guid>
					<description>I must confess I haven'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'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 <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </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. <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-13</link>
		<author>Sebastian</author>
		<pubDate>Fri, 23 Mar 2007 14:26:42 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#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'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'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'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-17</link>
		<author>Peter Cooper</author>
		<pubDate>Fri, 23 Mar 2007 22:14:51 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-17</guid>
					<description>How'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-18</link>
		<author>Sebastian</author>
		<pubDate>Fri, 23 Mar 2007 22:51:33 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#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: Ruby Rocks -- à la Francois Montagne &#124; Montreal Tech Watch</title>
		<link>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#comment-341</link>
		<author>Ruby Rocks -- à la Francois Montagne &#124; Montreal Tech Watch</author>
		<pubDate>Mon, 13 Aug 2007 18:49:15 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/an-introduction-to-code-blocks/#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>[&#8230;] 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 [&#8230;]</p>
]]></content:encoded>
				</item>
</channel>
</rss>
