我很難找出這個挑戰。以下是我有:rspec Ruby要插入到Hash的方法
class Dictionary
attr_accessor :entries
def initialize
@x = Hash.new
end
def entries
@x
end
def add(hash)
@x.merge!(hash)
end
end
@d=Dictionary.new
@d.add('fish' => 'aquatic animal')
puts @d.entries
我越來越=> 「fishaquatic動物」
我希望得到=> { '魚'=> '水生動物'}
這樣做!只有這是...我試圖滿足rpec代碼...他們有'@ d.add('fish'=>'aquatic animal')'......任何想法?謝謝@Levi – 2013-02-13 01:47:01
我用一個適用於我的示例測試更新了答案。你有不同的行爲嗎? – 2013-02-13 02:02:27
這一個工作..謝謝!!我看到的唯一區別是你的代碼沒有'attr_accessor:entries',你知道爲什麼會導致不同的結果嗎? – 2013-02-13 03:09:13