我想让sushiable?
返回initialise
中设置的实例变量,但我似乎无法让它工作。我做错了什么?
attr_accessor :weight, :value, :sushiable?
def initialize (weight,value, sushiable?)
@weight = weight
@value = value
@sushiable = sushiable?
end
# def sushiable?
# false
# end
答案 0 :(得分:4)
使用?
仅对方法名称有效,对变量无效。所以,正确的方法是:
attr_accessor :weight, :value, :sushiable
def initialize (weight, value, sushiable)
@weight = weight
@value = value
@sushiable = sushiable
end
def sushiable?
sushiable
end