From: David Alan Black Date: 2002-01-01T01:41:22+09:00 Subject: [ruby-talk:29867] Re: Proc.class vs yield Hi -- On Mon, 31 Dec 2001, Michael Lucas-Smith wrote: > That's a good solution, thanks. > But I have to say I'm slightly confused as to why everybody seems so > against having the Ruby language hide the fact that you're either > dealing with a block or a proc. > Why must there only be one? Why do you have to use the keyword proc to > define a new proc from a block? > > The common case is to pass a block around, but when you need it to act > like an object, you have to turn it in to a proc. I'm all for > optimisation. So why can't Ruby do it for you - if the method takes >1 > parameters and you hand it some blocks, can't it turn them in to procs > for you? (taking in to account the & logic to accept the yield block as > a proc) Hmmm... I wonder whether part of what you're not liking is the fact that the {} operator is overloaded: it's a block constructor and also a hash constructor. So there needs to be a way to deal with things like: some_method( { "hi" }, { "one" => 1 }, { |x| puts x }) not to mention: some_method { "hi" } # block or (malformed) hash argument? Could the benefits of having a hash constructor reconcile you to having to jump through a hoop to go from block to Proc? :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav