我如何完成以下操作?
class Monkey
attr_setter(:name, new_name)
if is_supported(@version)
@name = new_name
else
raise ":name is not supported for #{@version.to_s}"
end
end
attr_getter(:name)
if is_supported(@version)
return @name
else
raise ":name is not supported for #{@version.to_s}"
end
end
end
答案 0 :(得分:1)
class Monkey
attr_reader :name
def name=(new_name)
if is_supported(@version)
@name = new_name
else
raise ":name is not supported for #{@version.to_s}"
end
end
end