<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-3718956085911858962.post4052962837996628376..comments</id><updated>2011-06-05T19:10:43.551+05:30</updated><category term='barcamp'/><category term='continuous integration'/><category term='news'/><category term='quirks'/><category term='web'/><category term='books'/><category term='bug'/><category term='recruiting'/><category term='registry'/><category term='spawn'/><category term='gwt'/><category term='methodology'/><category term='symlinks'/><category term='innovative'/><category term='dzone'/><category term='DCB1'/><category term='junction'/><category term='css'/><category term='evolving'/><category term='devcampbangalore'/><category term='utf8'/><category term='rails'/><category term='video'/><category term='c42'/><category term='.net'/><category term='performance'/><category term='cc.rb'/><category term='xp'/><category term='training'/><category term='rant'/><category term='undernet'/><category term='resharper'/><category term='JSNI'/><category term='scala'/><category term='java'/><category term='refactoring'/><category term='activ'/><category term='anti-pattern'/><category term='security'/><category term='intro'/><category term='humour'/><category term='thoughtworks'/><category term='intellij'/><category term='india'/><category term='barcampbangalore5'/><category term='hackdayindia'/><category term='django'/><category term='links'/><category term='mochikit'/><category term='hiring'/><category term='mvc'/><category term='leisure'/><category term='interview'/><category term='photo'/><category term='brug'/><category term='twb'/><category term='opinion'/><category term='content repository'/><category term='digg'/><category term='practices'/><category term='mongrel'/><category term='mac'/><category term='offshore'/><category term='darkness'/><category term='OOP'/><category term='quality'/><category term='fun'/><category term='feedburner'/><category term='testing'/><category term='release'/><category term='architecture'/><category term='musings'/><category term='nasscom'/><category term='gotcha'/><category term='prototype'/><category term='ide'/><category term='ruby'/><category term='rdt'/><category term='dragdrop'/><category term='jcr'/><category term='skills'/><category term='javascript'/><category term='bangpypers'/><category term='tomcat'/><category term='event'/><category term='conference'/><category term='osx'/><category term='sysinternals'/><category term='announcement'/><category term='GI'/><category term='bangalore'/><category term='unconference'/><category term='agile'/><category term='python'/><category term='plugin'/><category term='analysis'/><category term='javaone'/><category term='browser'/><category term='enterprise'/><category term='ci'/><category term='barcampbangalore4'/><category term='windows'/><category term='irc'/><category term='tdd'/><category term='tweak'/><category term='recruitment'/><category term='rubyconf'/><category term='jackrabbit'/><category term='hack'/><category term='dcb2'/><category term='oss'/><category term='cycle'/><category term='tool'/><category term='feedflare'/><category term='REST'/><category term='feedflareunit'/><category term='ajax'/><category term='howto'/><category term='programming'/><category term='bcb4'/><category term='startup'/><category term='deployment'/><category term='tw'/><category term='lucene'/><category term='metaprogramming'/><category term='2010'/><category term='noob'/><category term='dining table'/><category term='YUI'/><category term='tibco'/><category term='versioning'/><category term='literature'/><category term='jquery'/><category term='activeresource'/><category term='cool'/><category term='rubyconf2011'/><category term='blogger'/><category term='call'/><category term='twitter'/><category term='functional programming'/><category term='search'/><category term='mingle'/><category term='microsoft'/><category term='book review verdict:read'/><category term='jruby'/><category term='goldberg'/><category term='wrest'/><title type='text'>Comments on Electric Sheep Blog: Ruby blocks gotchas</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.sidu.in/feeds/4052962837996628376/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html'/><author><name>Sidu</name><uri>http://www.blogger.com/profile/11938300811286150164</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/74/186326016_765e6e2222_s.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-5777464823596350848</id><published>2011-06-05T19:10:31.552+05:30</published><updated>2011-06-05T19:10:31.552+05:30</updated><title type='text'>I know it&amp;#39;s been a while since this post was f...</title><content type='html'>I know it&amp;#39;s been a while since this post was first published, but since people are still commenting on it and noone&amp;#39;s suggested possibly the most awesome solution to this, here goes.&lt;br /&gt;&lt;br /&gt;I know that the point of the post wasn&amp;#39;t to implement a profiling/benchmarking framework, but what you&amp;#39;re trying to achieve could be implemented using a trivial &lt;a href="http://joyeur.com/2007/05/07/dtrace-for-ruby-is-available/" rel="nofollow"&gt;DTrace&lt;/a&gt; script =&amp;gt; &lt;a href="http://svn.joyent.com/opensource/dtrace/ruby/examples/rb_functime.d" rel="nofollow"&gt;rb_functime.d&lt;/a&gt;. Since you&amp;#39;re on OSX, you should already have libdrace (as well as its dtrace frontend utility), but if you insist on going ruby all the way, there&amp;#39;s always &lt;a href="https://github.com/chrisa/ruby-dtrace" rel="nofollow"&gt;ruby-dtrace&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;On a more interesting note, DTrace probes for Ruby were released just a few months before your blog post! :P</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5777464823596350848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5777464823596350848'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1307281231552#c5777464823596350848' title=''/><author><name>Saager Mhatre</name><uri>http://www.blogger.com/profile/03869587109666583246</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://lh4.google.com/saager.mhatre/RwM-4CsYevI/AAAAAAAAArA/YftcTXPgpc8/s144/dexter.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1317165742'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-5721564728573511765</id><published>2011-06-05T18:57:54.626+05:30</published><updated>2011-06-05T18:57:54.626+05:30</updated><title type='text'></title><content type='html'>This comment has been removed by the author.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5721564728573511765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5721564728573511765'/><author><name>Saager Mhatre</name><uri>http://www.blogger.com/profile/03869587109666583246</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://lh4.google.com/saager.mhatre/RwM-4CsYevI/AAAAAAAAArA/YftcTXPgpc8/s144/dexter.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.contentRemoved' value='true'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1317165742'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-8368612773540740506</id><published>2011-05-05T18:41:07.132+05:30</published><updated>2011-05-05T18:41:07.132+05:30</updated><title type='text'>Thanks for the post! I&amp;#39;ve also written an arti...</title><content type='html'>Thanks for the post! I&amp;#39;ve also written an article about &lt;a href="http://blog.mostof.it/why-ruby-part-two-blocks-and-closures/" rel="nofollow"&gt;Ruby blocks and closures&lt;/a&gt; with code examples.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8368612773540740506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8368612773540740506'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1304601067132#c8368612773540740506' title=''/><author><name>Ochronus</name><uri>http://www.blogger.com/profile/16313443099316216977</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://1.bp.blogspot.com/_B7KnNXbxmEs/TNkdxhvHuNI/AAAAAAAAAp0/6XeRPAMiqxY/S220/zen_circle.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2109258465'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-9146285890748618465</id><published>2011-01-25T19:29:36.493+05:30</published><updated>2011-01-25T19:29:36.493+05:30</updated><title type='text'>Still some useful info in this post and comments. ...</title><content type='html'>Still some useful info in this post and comments.  Was fighting a similar problem and this helped.&lt;br /&gt;&lt;br /&gt;In 1.8.7, this was working:&lt;br /&gt;&lt;br /&gt;... do |*a, &amp;amp;blk|&lt;br /&gt;...&lt;br /&gt; send meth, *a, &amp;amp;blk&lt;br /&gt;&lt;br /&gt;But 1.8.6 didn&amp;#39;t like this syntax.&lt;br /&gt;After much playing around, I found I needed a &amp;quot;passthrough block&amp;quot; :&lt;br /&gt;&lt;br /&gt;... do |*a| ...&lt;br /&gt;send meth, *a { yield }&lt;br /&gt;&lt;br /&gt;Hope this comment saves someone else some time.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/9146285890748618465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/9146285890748618465'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1295963976493#c9146285890748618465' title=''/><author><name>Gerry</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1006145955'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-3685781141558788698</id><published>2010-11-07T05:35:36.578+05:30</published><updated>2010-11-07T05:35:36.578+05:30</updated><title type='text'>This is 3 years after your original post hehe...an...</title><content type='html'>This is 3 years after your original post hehe...anyway..&lt;br /&gt;&lt;br /&gt;I don&amp;#39;t believe this behaviour is an inconsistency. It is a result of blocks being captured by closures and so the &amp;#39;yield&amp;#39; instead invokes any extant block in the enclosing context.&lt;br /&gt;&lt;br /&gt;See here: http://banisterfiend.wordpress.com/2010/11/06/behavior-of-yield-in-define_method/</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/3685781141558788698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/3685781141558788698'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1289088336578#c3685781141558788698' title=''/><author><name>banisterfiend</name><uri>http://banisterfiend.wordpress.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1471832988'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-5970695189001747397</id><published>2008-07-31T04:53:00.000+05:30</published><updated>2008-07-31T04:53:00.000+05:30</updated><title type='text'>I really don&amp;#39;t think it can get any simpler th...</title><content type='html'>I really don&amp;#39;t think it can get any simpler than this:&lt;BR/&gt;&lt;BR/&gt;x = lambda do&lt;BR/&gt;  puts &amp;#39;hello&amp;#39;&lt;BR/&gt;  yield&lt;BR/&gt;end&lt;BR/&gt;&lt;BR/&gt;x.call { puts &amp;#39;world&amp;#39; }&lt;BR/&gt;&lt;BR/&gt;And the above example still doesn&amp;#39;t work with ruby 1.9.0 (2008-07-31 revision 18282) [x86_64-linux].&lt;BR/&gt;&lt;BR/&gt;hello&lt;BR/&gt;test.rb:3:in `block in &amp;lt;main&amp;gt;&amp;#39;: no block given (yield) (LocalJumpError)&lt;BR/&gt; from test.rb:6:in `call&amp;#39;&lt;BR/&gt; from test.rb:6:in `&amp;lt;main&amp;gt;&amp;#39;&lt;BR/&gt;&lt;BR/&gt;So as far as I can see, no, Ruby 1.9 most definitely does not (yet) allow me to IMPLICITLY pass a block to another block, unless we are going to argue that lambdas are some kind of special case.&lt;BR/&gt;&lt;BR/&gt;A new thing Ruby 1.9 can do is allow me to EXPLICITLY pass a block. This works in Ruby 1.9 (but didn&amp;#39;t work in 1.8)&lt;BR/&gt;&lt;BR/&gt;x = lambda do |&amp;amp;block|&lt;BR/&gt;  puts &amp;#39;hello&amp;#39;&lt;BR/&gt;  block.call&lt;BR/&gt;end&lt;BR/&gt;&lt;BR/&gt;x.call { puts &amp;#39;world&amp;#39; }&lt;BR/&gt;&lt;BR/&gt;Functionally, this is good enough. But the whole business with |&amp;amp;block| is ugly and inconsistent with the use of yield inside methods. Wouldn&amp;#39;t allowing the use of yield inside a lambda be nicer? Or am I missing something here?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5970695189001747397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5970695189001747397'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1217460180000#c5970695189001747397' title=''/><author><name>Benjamin Kay</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-307925889'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-437826823072719330</id><published>2008-06-30T00:38:00.000+05:30</published><updated>2008-06-30T00:38:00.000+05:30</updated><title type='text'>Kudos on tackling a tricky subject with this post....</title><content type='html'>Kudos on tackling a tricky subject with this post. I'd like to offer a couple of "clarifications" which hopefully will help people.&lt;BR/&gt;&lt;BR/&gt;The reason the implicit version is faster is because you are repeatedly constructing the Proc every time in the explicit version. &lt;BR/&gt;&lt;BR/&gt;If you never access the Proc directly, why add the overhead of constructing an object? This way, you only pay for what you need.&lt;BR/&gt;&lt;BR/&gt;I don't really see how this violates the "everything is an object" rule, since as soon as you try to access it, the block becomes an object. :)&lt;BR/&gt;&lt;BR/&gt;Also: the problem with passing blocks to blocks is not due to define_method, just blocks. A similar difference exists with default arguments. Method arguments and block arguments will operate the same way (I think) in Ruby 1.9.&lt;BR/&gt;&lt;BR/&gt;IMHO, the biggest inconsistency with blocks, especially post 1.9, is one you haven't alluded to here, which is that return behaves differently between Proc.new and lambda.&lt;BR/&gt;&lt;BR/&gt;See:&lt;BR/&gt;http://tinyurl.com/29a28d&lt;BR/&gt;&lt;BR/&gt;When returning from blocks, passed explicitly or implicitly, return takes you all the way out of the calling method. That is, they behave like Proc.new (which makes sense), not lambda.&lt;BR/&gt;&lt;BR/&gt;This is arguably necessary to support the POLS when dealing with inline blocks (say, with #each). You don't expect return to just pop you out of the block, you expect to return from the method. Not sure if that changes in 1.9?&lt;BR/&gt;&lt;BR/&gt;Anyway, thanks again for the interesting article!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/437826823072719330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/437826823072719330'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1214766480000#c437826823072719330' title=''/><author><name>Dan Yoder</name><uri>http://rubywaves.com</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2041872973'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-7645699998986099324</id><published>2008-06-29T15:38:00.000+05:30</published><updated>2008-06-29T15:38:00.000+05:30</updated><title type='text'>Why are you handrolling your own dubious benchmark...</title><content type='html'>Why are you handrolling your own dubious benchmarking class?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/7645699998986099324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/7645699998986099324'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1214734080000#c7645699998986099324' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1314251636'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-8070348817213009224</id><published>2008-03-15T22:50:00.000+05:30</published><updated>2008-03-15T22:50:00.000+05:30</updated><title type='text'>Looks like this post is still alive and people rea...</title><content type='html'>Looks like this post is still alive and people read it.. A post that clarifies a lot more things about blocks, closures, procs in ruby is here http://innig.net/software/ruby/closures-in-ruby.rb</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8070348817213009224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8070348817213009224'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1205601600000#c8070348817213009224' title=''/><author><name>Sudhindra Rao</name><uri>http://www.blogger.com/profile/07437146809844632919</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1446488339'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-7189681035663889221</id><published>2008-01-02T21:15:00.000+05:30</published><updated>2008-01-02T21:15:00.000+05:30</updated><title type='text'>I see four problems with blocks in Ruby 1.8:&lt;br&gt;&lt;b...</title><content type='html'>I see four problems with blocks in Ruby 1.8:&lt;BR/&gt;&lt;BR/&gt;1. Can't pass a block to a block, thus causing problems with define_method and similar.&lt;BR/&gt;&lt;BR/&gt;2. The differences between Proc.new, proc, lambda, and implicit blocks. I have a hard time keeping the differences straight, and try to use only lambda and implicit blocks.&lt;BR/&gt;&lt;BR/&gt;3. The performance difference between explicit and implicit block-passing.&lt;BR/&gt;&lt;BR/&gt;4. The only way to pass more than one block to a method is to pass (all but one of) them as explicit procs/lambdas.&lt;BR/&gt;&lt;BR/&gt;Of these, the first one is definitely fixed in Ruby 1.9, and I think the second one is as well. The third is a quirk of MRI, and it would be worth running some benchmarks in other Ruby implementations (JRuby, Rubinius, IronRuby...). The fourth comes up rarely enough that I have a hard time suggesting a more convenient syntax, even though it annoys me on occasion.&lt;BR/&gt;&lt;BR/&gt;In addition, an implicit block can be captured into a Proc object:&lt;BR/&gt;&lt;BR/&gt;def foo&lt;BR/&gt;  Proc.new&lt;BR/&gt;end&lt;BR/&gt;&lt;BR/&gt;bar = foo { |arg| puts "You called me with #{arg}" }&lt;BR/&gt;bar.call(22)&lt;BR/&gt;bar.call(99)&lt;BR/&gt;&lt;BR/&gt;I might argue that the implicit block and yield construct in Ruby is a mistake to begin with, but it improves the readability of iteration methods. That one case may or may not justify the complication of two parallel block-passing constructs, however.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/7189681035663889221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/7189681035663889221'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1199288700000#c7189681035663889221' title=''/><author><name>Gregory</name><uri>http://www.blogger.com/profile/01377458805247260071</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-924606967'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-8497619841698858327</id><published>2007-11-30T00:46:00.000+05:30</published><updated>2007-11-30T00:46:00.000+05:30</updated><title type='text'>You're right, I've been investigating something si...</title><content type='html'>You're right, I've been investigating something similar and I stumble upon the same caveats that you did. If someone knows some little known black magic here would be great.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8497619841698858327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/8497619841698858327'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196363760000#c8497619841698858327' title=''/><author><name>Fabio Akita, PMP</name><uri>http://www.blogger.com/profile/05539202931163964720</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://photos1.blogger.com/blogger/4643/1852/1600/akitaonrails.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-821334025'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-5128551844828490808</id><published>2007-11-27T15:35:00.000+05:30</published><updated>2007-11-27T15:35:00.000+05:30</updated><title type='text'>re: Blocks violate the 'everything is an object' r...</title><content type='html'>re: Blocks violate the 'everything is an object' rule in Ruby for performance reasons. They only become objects when bound to a variable.&lt;BR/&gt;&lt;BR/&gt;I don't think this is correct.  Two reasons: 1 - I have read that ruby blocks are not first class objects due to not wanting to expose the implementation to allow for future change.  2 - I'm an old Smalltalk'er.  Blocks are first class objects in Smalltalk and a Smalltalk VM of 15 years ago in most cases outperforms a Ruby interpreter of today; including dynamic block dispatches. enjoy!!!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5128551844828490808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5128551844828490808'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196157900000#c5128551844828490808' title=''/><author><name>Jon Hancock</name><uri>http://www.blogger.com/profile/08064528668252467611</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-95288334'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-924945239980222681</id><published>2007-11-26T23:50:00.000+05:30</published><updated>2007-11-26T23:50:00.000+05:30</updated><title type='text'>@anonymous #1 - you're right, it &lt;i&gt;is&lt;/i&gt; clearer...</title><content type='html'>@anonymous #1 - you're right, it &lt;I&gt;is&lt;/I&gt; clearer your way. Thanks!&lt;BR/&gt;&lt;BR/&gt;@anonymous #2 - thanks, for the tip, that's worthy of an update to the post.&lt;BR/&gt;&lt;BR/&gt;@anonymous #3 - I didn't read it anywhere. What I &lt;I&gt;did&lt;/I&gt; read was 'pure OO' and 'everything is an object'. Nothing mentioned exceptions to these rules.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/924945239980222681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/924945239980222681'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196101200000#c924945239980222681' title=''/><author><name>Sidu</name><uri>http://www.blogger.com/profile/11938300811286150164</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://static.flickr.com/74/186326016_765e6e2222_s.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-331438855'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-2205626857179995688</id><published>2007-11-26T22:08:00.000+05:30</published><updated>2007-11-26T22:08:00.000+05:30</updated><title type='text'>I really dont think anyone ever wrote anything abo...</title><content type='html'>I really dont think anyone ever wrote anything about blocks being objects. Where did you read that?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/2205626857179995688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/2205626857179995688'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196095080000#c2205626857179995688' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2002847396'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-4395543111197408517</id><published>2007-11-26T14:41:00.000+05:30</published><updated>2007-11-26T14:41:00.000+05:30</updated><title type='text'>Ruby 1.9 block will accept a block as a parameter....</title><content type='html'>Ruby 1.9 block will accept a block as a parameter.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/4395543111197408517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/4395543111197408517'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196068260000#c4395543111197408517' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-330600694'/></entry><entry><id>tag:blogger.com,1999:blog-3718956085911858962.post-5895151754584194294</id><published>2007-11-25T21:59:00.000+05:30</published><updated>2007-11-25T21:59:00.000+05:30</updated><title type='text'>def foo(*args)&lt;br&gt; blk = args.delete_at(-1) # We k...</title><content type='html'>def foo(*args)&lt;BR/&gt; blk = args.delete_at(-1) # We know that the last argument &lt;BR/&gt;                          # is the bound block&lt;BR/&gt; blk.call(args.join(' '))  &lt;BR/&gt;end&lt;BR/&gt;&lt;BR/&gt;looks unnecessary clumsy. Why not:&lt;BR/&gt;&lt;BR/&gt;def foo(blk, *args)&lt;BR/&gt;   blk.call(args.join(' '))&lt;BR/&gt;end</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5895151754584194294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3718956085911858962/4052962837996628376/comments/default/5895151754584194294'/><link rel='alternate' type='text/html' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html?showComment=1196008140000#c5895151754584194294' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html' ref='tag:blogger.com,1999:blog-3718956085911858962.post-4052962837996628376' source='http://www.blogger.com/feeds/3718956085911858962/posts/default/4052962837996628376' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1594104624'/></entry></feed>
