Why do you need the intermediate step at all? This is surely easier,
but it depends on your requirements
properties = [:a,:b,:c]
attributes = {}
properties.each_with_index {|p,i| attributes[p] = i + 1}
puts attributes.inspect
-D
On 24/07/2010 4:10PM, Ashley Moran wrote:
Hi all
This snippet:
properties = [:a, :b, :c]
counter = (1..properties.length).each
attributes = properties.inject({}) { |attribs, property|
attribs[property] = counter.next
attribs
}
puts attributes
produces this output:
{:a=>1, :b=>2, :c=>3}
But I'm sure you can do much better in Ruby 1.9. Anyone know how and wanna
show me? :)
Cheers
Ash
--
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.