<?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: More Advanced Ruby Method Arguments &#8211; Hashes And Block Basics</title>
	<atom:link href="http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/</link>
	<description>For the betterment of the software craft...</description>
	<lastBuildDate>Mon, 06 Sep 2010 12:59:05 +1000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Alan Skorkin</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-6079</link>
		<dc:creator>Alan Skorkin</dc:creator>
		<pubDate>Fri, 16 Jul 2010 00:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-6079</guid>
		<description>No worries, I am glad you find it helpful</description>
		<content:encoded><![CDATA[<p>No worries, I am glad you find it helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emerson Lackey</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-6072</link>
		<dc:creator>Emerson Lackey</dc:creator>
		<pubDate>Fri, 09 Jul 2010 02:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-6072</guid>
		<description>I find myself back at this post at least once a month. Landmark to say the least... thanks for the great writeup and pleasing syntax highlighter!</description>
		<content:encoded><![CDATA[<p>I find myself back at this post at least once a month. Landmark to say the least&#8230; thanks for the great writeup and pleasing syntax highlighter!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dubl</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-3264</link>
		<dc:creator>Dubl</dc:creator>
		<pubDate>Sat, 17 Oct 2009 00:17:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-3264</guid>
		<description>ok then so to extend the thought, here&#039;s how to turn a block into an object and use it:

def objectify(&amp;ablock)
ablock
end

block_object=objectify{&#124;x&#124; x*2}

block_object.call(5) #=&gt;10

def use(block_obj,param)
puts block_obj.call(param)
end

use(block_object,4)  # =&gt;8
use(block_object,3) #=&gt;6
block_object=objectify{&#124;x&#124; x*10}
use(block_object,4) #=&gt;40</description>
		<content:encoded><![CDATA[<p>ok then so to extend the thought, here&#8217;s how to turn a block into an object and use it:</p>
<p>def objectify(&amp;ablock)<br />
ablock<br />
end</p>
<p>block_object=objectify{|x| x*2}</p>
<p>block_object.call(5) #=&gt;10</p>
<p>def use(block_obj,param)<br />
puts block_obj.call(param)<br />
end</p>
<p>use(block_object,4)  # =&gt;8<br />
use(block_object,3) #=&gt;6<br />
block_object=objectify{|x| x*10}<br />
use(block_object,4) #=&gt;40</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roger</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-3222</link>
		<dc:creator>roger</dc:creator>
		<pubDate>Thu, 08 Oct 2009 19:10:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-3222</guid>
		<description>also checkout &quot;named arguments&quot;
http://github.com/maca/arguments</description>
		<content:encoded><![CDATA[<p>also checkout &#8220;named arguments&#8221;<br />
<a href="http://github.com/maca/arguments" rel="nofollow">http://github.com/maca/arguments</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ennuyer.net &#187; Blog Archive &#187; Rails Reading - August 30, 2009</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2406</link>
		<dc:creator>Ennuyer.net &#187; Blog Archive &#187; Rails Reading - August 30, 2009</dc:creator>
		<pubDate>Sun, 30 Aug 2009 20:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2406</guid>
		<description>[...]  More Advanced Ruby Method Arguments – Hashes And Block Basics  [...]</description>
		<content:encoded><![CDATA[<p>[...]  More Advanced Ruby Method Arguments – Hashes And Block Basics  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Skorkin</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2354</link>
		<dc:creator>Alan Skorkin</dc:creator>
		<pubDate>Thu, 27 Aug 2009 13:09:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2354</guid>
		<description>I haven&#039;t really considered default arguments when using hashes, but it makes sense that you should be able to do it and from what you say it is definitely a lot more verbose which is a point against it (if you need default values when using hashes as that is).</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t really considered default arguments when using hashes, but it makes sense that you should be able to do it and from what you say it is definitely a lot more verbose which is a point against it (if you need default values when using hashes as that is).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guoliang Cao</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2352</link>
		<dc:creator>Guoliang Cao</dc:creator>
		<pubDate>Thu, 27 Aug 2009 12:32:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2352</guid>
		<description>Nice writeup!

I would add one more thing though: if use hash as argument, default values are set differently. 

E.g. for regular argument with default value, it will look like this

def do_something timeout = 30, retry = 3
...
end

If use hash, in order to achieve same behavior, it should be

def do_something options = {}
default_options = {:timeout =&gt; 30, :retry =&gt; 3}
options = default_options.merge(options)
...
end

That&#039;s a lot more typing.</description>
		<content:encoded><![CDATA[<p>Nice writeup!</p>
<p>I would add one more thing though: if use hash as argument, default values are set differently. </p>
<p>E.g. for regular argument with default value, it will look like this</p>
<p>def do_something timeout = 30, retry = 3<br />
&#8230;<br />
end</p>
<p>If use hash, in order to achieve same behavior, it should be</p>
<p>def do_something options = {}<br />
default_options = {:timeout =&gt; 30, :retry =&gt; 3}<br />
options = default_options.merge(options)<br />
&#8230;<br />
end</p>
<p>That&#8217;s a lot more typing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Skorkin</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2343</link>
		<dc:creator>Alan Skorkin</dc:creator>
		<pubDate>Thu, 27 Aug 2009 02:27:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2343</guid>
		<description>I wasn&#039;t aware you could do that with blocks, I might dig some more into that, sounds like a cool feature, thanks.

I am aware of first class function and yeah I agree with you if an argument is a function it certainly makes sense for it to be able to have arguments. I guess my colorful way of making a point wasn&#039;t as clever as I thought it was :).</description>
		<content:encoded><![CDATA[<p>I wasn&#8217;t aware you could do that with blocks, I might dig some more into that, sounds like a cool feature, thanks.</p>
<p>I am aware of first class function and yeah I agree with you if an argument is a function it certainly makes sense for it to be able to have arguments. I guess my colorful way of making a point wasn&#8217;t as clever as I thought it was :).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Matthew Sutton</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2337</link>
		<dc:creator>Luke Matthew Sutton</dc:creator>
		<pubDate>Wed, 26 Aug 2009 23:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2337</guid>
		<description>&quot;Blocks Are NOT Method Arguments&quot;

Well, yes they _can_ be actually. If you define a method that accepts a block, you can create a parameter for it. You&#039;re then free to call it, or pass it to another method, just like any other argument.

The only kink is the need to prefix the block parameter with &#039;&amp;&#039; and that you can only have the one.

def accept_block(first, second, &amp;blk)
  blk.call(&quot;do something block&quot;)
end

Most iterators just use the yield construct, in which case the block isn&#039;t assigned to an argument. 

&quot;Does it really make sense for arguments to have arguments?&quot;

Yep, those are called first-class-functions in other languages. A block is essentially an anonymous function which you pass into a method -- with some special syntax to make it easier and look neater.</description>
		<content:encoded><![CDATA[<p>&#8220;Blocks Are NOT Method Arguments&#8221;</p>
<p>Well, yes they _can_ be actually. If you define a method that accepts a block, you can create a parameter for it. You&#8217;re then free to call it, or pass it to another method, just like any other argument.</p>
<p>The only kink is the need to prefix the block parameter with &#8216;&amp;&#8217; and that you can only have the one.</p>
<p>def accept_block(first, second, &amp;blk)<br />
  blk.call(&#8220;do something block&#8221;)<br />
end</p>
<p>Most iterators just use the yield construct, in which case the block isn&#8217;t assigned to an argument. </p>
<p>&#8220;Does it really make sense for arguments to have arguments?&#8221;</p>
<p>Yep, those are called first-class-functions in other languages. A block is essentially an anonymous function which you pass into a method &#8212; with some special syntax to make it easier and look neater.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop &#8211; August 26, 2009 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://www.skorks.com/2009/08/more-advanced-ruby-method-arguments-hashes-and-blocks/comment-page-1/#comment-2321</link>
		<dc:creator>Dew Drop &#8211; August 26, 2009 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Wed, 26 Aug 2009 12:59:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.skorks.com/?p=1088#comment-2321</guid>
		<description>[...] More Advanced Ruby Method Arguments – Hashes And Block Basics (Alan Skorkin) [...]</description>
		<content:encoded><![CDATA[<p>[...] More Advanced Ruby Method Arguments – Hashes And Block Basics (Alan Skorkin) [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
