I want to create hash that will look like this:
{nil => "Cat", 0 => "Dog", 1 => "1", ... 16 => "16"}
And this is how I do it:
hash = { nil => "Cat",0 => "Dog" }
(1..16).to_a.each { |e| hash[e] = e.to_s }
And this just looks ugly. Is there a better way to achieve this (in version 1.8.7)?
Thanks
How about:
This works in both 1.8.7 and 1.9.2.