[LRUG] ShRUG Golf update

Jordi Noguera Leon jordinoguera83 at gmail.com
Thu May 12 02:36:08 PDT 2011


>
> 1. Enumerable#inject doesn't need a block, it actually takes 2 params, a
> initial value and a symbol as an argument.  Each iteration the symbol is the
> method that'll be called on the accumulator and passed the current element.
>  Also if you don't supply an initial element then it'll use the first
> element of the enumerable.  So you can turn
>
> array.inject(0) {|s, i| s + i}
>
> into
>
> array.inject(:+)
>

Into:
array.inject :+

:P
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110512/22d28171/attachment.html>


More information about the Chat mailing list