3
迎接所有人! 我想通过一个类来描述了每一种产品:Ruby类中的可继承属性
# Base product class
class BaseProduct
prop :name, :price # Common properties for all inheritable products
end
class Cellphone < BaseProduct
prop :imei # Concrete property for this product
end
class Auto < BaseProduct
prop :max_speed, :color # Concrete properties for this product
end
c = Cellphone.new
c.prop_names # => [:name, :price, :imei]
a = Auto.new
c.prop_names # => [:name, :price, :max_speed, :color]
那么,如何实现这一点?我花了3天,但没有得到工作的代码(