0
嘗試創建將鍵值對添加到散列的簡單方法時,獲取錯誤數量的參數錯誤(1代表2)。使用紅寶石1.9.3。創建一種將鍵值對添加到散列的方法
@roommates = {} # => {}
def dic(per, desc) # ~> ArgumentError: wrong number of arguments (1 for 2)
@roommates[per] = desc
end
p dic("beni" => "messy")
ArgumentError wrong number of arguments (1 for 2)
/Users/mwsage/Desktop/programs/p1weekend/dictionary.rb:13:in `dic'
/Users/mwsage/Desktop/programs/p1weekend/dictionary.rb:21:in `<main>'
另外使用@ roommates.store(人,定義)
感覺像我曾嘗試的參數的每個組合(1或2)作爲符號或字符串,定義當試圖該方法以及何時嘗試發送參數。
這樣做的目的是簡單地能夠添加室友和描述,並且必須在哈希中。
請幫助這個讓我發瘋的非常簡單的問題。