jweirich / one.net writes:

> Then we can rewrite matching_sum into ...
> 
>   def matching_sum (aSum)
>     if_none (@summary.detect {|each| each.name == aSum.name}) do
>       result = Sum.new (aSum.name, 0)
>       @summary << result
>       result
>     end
>   end
> 
> There, that captures some of the flavor of the Smalltalk version.
> 
> Is it worthwhile?  Is it clearer?  I'm not sure, but I thought it was
> interesting and that this list might enjoy it.

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

    class Object
      def ifNil?(expr)
        self
      end
    end
  
    def nil.ifNil?(expr)
      expr
    end

    x = a.detect {|i| i == 7} .ifNil? 99    #=> 99
    x = a.detect {|i| i == 3} .ifNil? 99    #=> 3