On Sat, Jul 24, 2010 at 4:48 PM, Caius Durling <[email protected]> wrote:
> That's a bit long-winded, even in 1.8.7.
>
> properties = [:a, :b, :c]
> attributes = properties.inject({}) {|hash, e| hash[e] =
> properties.index(e) + 1; hash }
>
> p attributes
> __END__
> {:b=>2, :c=>3, :a=>1}
>
> Obviously it outputs an unordered hash, given it's 1.8.7.
Must. Resist. Golf.
Oh well:
properties = [:a, :b, :c]
attributes = properties.inject({}) {|hash, e| hash.merge!({e => hash.size+1}) }
p.attributes
=> {:a=>1, :b=>2, :c=>3}
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.