From: Michael Lucas-Smith Date: 2001-06-16T09:26:26+09:00 Subject: [ruby-talk:16517] Re: Playing with Ruby Syntax (was: Initial thoughts about Ruby From a Smalltalk Programmer) > >Although hacking Kernel and NilClass is kinda fun, I probably wouldn't >do it in real life. I think the following code (using straight Ruby >out of the box) is still the most readable ... > > if item = [1,2,3].detect {|e| e>2} > puts "Found #{item}" > else > puts "Not Found" > end > I'm -extremely- greatful you brought this up. I realise now why it was that the method detect:ifFound:ifNone: was implemented in the first place in smalltalk. Temporary variables. In Smalltalk, to write a temporary variable is to cost you valuable coding space. | item | (item := someCollection.detect: [:e| e>2] ifNone: [nil]) isNil ifTrue: [ ... item is found ... ] ifFalse: [ ... not foudn ... ] But with Ruby.. it costs you nothing to include an extra temporary variable! .. you have just broken me free of one of my Smalltalk quirks. I'm not sure how I'm going to be able to face work on Monday though now! :) Michael Lucas-Smith