From: Eric Hodel Date: 2007-10-11T17:19:39+09:00 Subject: Re: Why does this use a block On Oct 11, 2007, at 24:12 , Anonymous wrote: > So I'm new to Ruby and I'm trying to use OptionParser to parse in some > command line arguments. I looked at some documentation on > OptionParser and there is something that's confusing me to no end. > In all the examples a block is being passed in to the constructor > of the OptionParser object. The constructor simply makes a yield > call, passing self as an argument. > > What is the point of this? Can we not convert > > opts = OptionParser.new() {|opts| body} > > To > > opts = OptionParser.new() > body > > ? This seems more natural to me. But the former seems like a common > Ruby idiom so I'm wondering what I am missing. It works both ways. Blocks are pretty, so people use them. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars