【发布时间】:2011-04-16 17:47:27
【问题描述】:
大家好! 我想用一个类来描述每一种产品:
# 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 天时间,但没有工作代码(
【问题讨论】:
标签: ruby class attributes class-attributes inherited