I want to add elements to my Hash lists, which can have more than one value. Here is my code. I don't know how I can solve it!
class dictionary
def initialize(publisher)
@publisher=publisher
@list=Hash.new()
end
def []=(key,value)
@list << key unless @list.has_key?(key)
@list[key] = value
end
end
dic = Dictionary.new
dic["tall"] = ["long", "word-2", "word-3"]
p dic
Many thanks in advance.
regards,
koko
Probably, you want to merge two Hashes?
I think this is what you're trying to do
Edit
Now avoids duplicate values thanks to
Array#uniq!
.