From: Michael Lucas-Smith Date: 2001-12-31T15:01:34+09:00 Subject: [ruby-talk:29813] Re: Proc.class vs yield HarryO wrote: > On Mon, 31 Dec 2001 16:19:48 +1100, Michael Lucas-Smith wrote: > > > >>The reason I'm bringing this up is because having a criteria block of >>code and a failure block of code si very common in Smalltalk >> > > I wonder whether your failure block could be replaced by the > throwing and catching of an exception? I realise, of course, > that the standard containers don't tend to throw exceptions > in this case. However, if you would like this behaviour, you > might be able to either derive your own classes from them, or > use Ruby's dynamic facilities to modify the behaviour of the > containers themselves. > > Just a thought ... and someone else who knows how things work > in ST may be able to clean it up to make it more palatable. > I may be mistaken, but it appears as though the exception throwing and catching is global within your namespace? when I read 'catch' and 'throw' in the reference manuals for 1.4, they don't seem to talk about a scope at all. Otherwise, you could end up writing some code along the lines of: def childrenOf (aPersonName, people) catch (:found) { |person| return person.children } catch (:none) { return Array.new } people.detect { |person| person.name = aPersonName } end but now the method is backwards and counter intuitive. Michael