From: "Aleksi Niemelä" Date: 2000-11-07T11:22:28+09:00 Subject: [ruby-talk:6092] Re: detect:ifNone: in Ruby > I like it. You can also mess around with the built in classes to get > an effect similar to Smalltalk's: > > a = [1,2,3,4,5] > > # #ifNil? returns the receiver, unless the receiver is nil, in > # which case it returns its argument .. > x = a.detect {|i| i == 7} .ifNil? 99 #=> 99 Don't forget the block form. x = a.detect {|i| i == 7}.ifNil { 99 } And I guess name should be without '?'. Otherwise great extension. (Is it ok to call it extension or am I overloading too much?) - Aleksi