From: David Alan Black Date: 2001-12-31T21:24:59+09:00 Subject: [ruby-talk:29843] Re: Proc.class vs yield Hi -- On Mon, 31 Dec 2001, Michael Lucas-Smith wrote: > What I'm really trying to point out is, it's a real shame that you are > forced to add this 'proc' thing before your blocks of code. To do > something similar to the three-block example in Ruby you'd have: > > def childrenOf (aPersonName, people) > return people.detect proc { |person| person.name = aPersonName }, > proc { |person| person.children}, > proc { Array.new } > end > > When really, I want to be able to write: > > def childrenOf (aPersonName, people) > return people.detect > { |person| person.name = aPersonName }, > { |person| person.children }, > { Array.new } > end I think you're adding an extra level of complexity by trying to turn plain lines of code into Proc objects, when you don't actually want to return a Proc object (let alone a list of Proc objects). True enough that idiomatic Ruby solutions won't take the same form as the Smalltalk ones... but they can definitely be achieved along pretty simple lines. See Jim W.'s for example. If you wanted to use an exception-based approach, you could do: # (untested) def children_of(who, people) begin people.detect { |p| p.name == who } .children rescue NoMethodError [] end end though it's presumably slower than just an if-clause. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav