0

我将如何完成以下任务?

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
4

1 回答 1

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
于 2013-06-07T18:38:08.487 回答