>>>>> "B" == Bruce Williams <bruce / codedbliss.com> writes:

>>> [1,2,3,4].reduce{ |a,b| a + b }

pigeon% ruby -ve 'p [1,2,3,4].inject { |a,b| a + b }'
ruby 1.8.0 (2002-12-24) [i686-linux]
10
pigeon% 

>>> %w|a lost puppy|.reduce{ |a,b| [a,b].join ' ' }

pigeon% ruby -ve 'p %w|a lost puppy|.inject { |a,b| [a,b].join " " }'
ruby 1.8.0 (2002-12-24) [i686-linux]
"a lost puppy"
pigeon% 

>>> [1,2,3,nil].reduce{ |a,b| a || b } # like Array#any?

pigeon% ruby -ve 'p [1,2,3,nil].inject { |a,b| a || b }'
ruby 1.8.0 (2002-12-24) [i686-linux]
1
pigeon% 


>>> [1,2,3,nil].reduce{ |a,b| a && b } # like Array#all?

pigeon% ruby -ve 'p [1,2,3,nil].inject { |a,b| a && b }'
ruby 1.8.0 (2002-12-24) [i686-linux]
nil
pigeon% 



Guy Decoux