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天,但沒有得到工作的代碼(