Re: Creating hashes with duplicate keys

Try this:

class Array
def keys_and_values(hash_value)
new_hash={}
for k in self
new_hash.update({k,hash_value})
end
return new_hash
end
end

same_value=‘identical’
my_array=[‘a’,‘b’,‘c’,‘d’]
hash=my_array.keys_and_values(same_value)
p hash

Best regards,

Axel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs