我希望有一个类和一些属性,您可以在初始化期间设置它们,也可以使用它的默认值。
class Fruit
attr_accessor :color, :type
def initialize(color, type)
@color=color ||= 'green'
@type=type ||='pear'
end
end
apple=Fruit.new(red, apple)
https://stackoverflow.com/questions/4554325
复制相似问题