You don't need the bang on merge.

[:a, :b, :c].inject({}) {|hash, e| hash.merge({e => hash.size+1})}


On Sat, Jul 24, 2010 at 5:13 PM, Will Jessop <[email protected]> wrote:
> On Sat, Jul 24, 2010 at 5:09 PM, Caius Durling <[email protected]> wrote:
>> Oh that's just too easy to golf. Counting the hash size means you no longer 
>> need to access the array within the block.
>>
>>    [:a, :b, :c].inject({}) {|hash, e| hash.merge!({e => hash.size+1}) } # => 
>> {:c=>3, :b=>2, :a=>1}
>
> OK, golf as in shorter but still readable :)
>
> Will
>
> --
> You received this message because you are subscribed to the Google Groups 
> "NWRUG" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/nwrug-members?hl=en.
>
>



-- 
Jim Neath - Manchester based Ruby on Rails Developer
http://jimneath.org

-- 
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nwrug-members?hl=en.

Reply via email to