更正此代碼,以便greet函數返回期望值。ruby def函數代碼不起作用
class Person
def initialize(name, other_name)
@name = name
@other_name = other_name
end
def greet(@other_name, @name)
"Hi #{@other_name}, my name is #{@name}"
end
end
期望值是多少?你的'greet'參數名稱不應該有'@'符號,因爲你插入了實例變量,所以你不需要它們。另外,當你的代碼有錯誤時,你應該發佈它。 –
我同意,你應該在提問時添加更多細節。它的措辭使它看起來像是一項家庭作業。 –
歡迎來到Stack Overflow。 「更正此代碼」?讓我們考慮Stack Overflow是什麼:在您給我們提供了適當的所需信息之後,我們會幫助您調試代碼中的問題。閱讀「[問]」和「[mcve]」,看看你是否做到了。 –