【发布时间】:2011-06-11 07:43:08
【问题描述】:
当我打开 IRB 并粘贴时
h = {"colors" => ["red", "blue", "green"],
"letters" => ["a", "b", "c" ]}
h.assoc("letters") #=> ["letters", ["a", "b", "c"]]
h.assoc("foo") #=> nil
我总是得到消息:
NoMethodError: undefined method `assoc' for {"letters"=>["a", "b", "c"], "colors"=>["red", "blue", "green"]}:Hash
from (irb):3
from :0
虽然这段代码取自http://ruby-doc.org/core/classes/Hash.html#M000760 我做错了什么?
【问题讨论】:
标签: ruby