我正在尝试重用 DataMapper 类中的方法。我认为这可能也是一个红宝石问题。
class Foo
include DataMapper::Resource
property :name
property ...
def self.special_name
self.all(:name => 'whatever')
end
end
class Bar
include DataMapper::Resource
property :name
property ...
def self.special_name
self.all(:name => 'whatever')
end
end
所以方法 special_name 将用于两个类,因为我想得到相同的结果。但它也使用了 DataMapper 方法,如“all”。那么你会怎么做呢?
谢谢