Ruby Inserting Key, Value elements in Hash.

Posted by kokogyi on Stack Overflow See other posts from Stack Overflow or by kokogyi
Published on 2010-05-04T15:57:32Z Indexed on 2010/05/04 16:18 UTC
Read the original article Hit count: 286

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about ruby

Related posts about hash