Method: Object#ancestral_trait
- Defined in:
- lib/m4dbi/traits.rb
#ancestral_trait ⇒ Object
builds a trait from all the ancestors, closer ancestors overwrite distant ancestors
class Foo
trait :one => :eins
trait :first => :erstes
end
class Bar < Foo
trait :two => :zwei
end
class Foobar < Bar
trait :three => :drei
trait :first => :overwritten
end
Foobar.ancestral_trait :two=>:zwei, :one=>:eins, :first=>:overwritten
60 61 62 63 64 65 66 67 |
# File 'lib/m4dbi/traits.rb', line 60 def ancestral_trait if respond_to?(:ancestors) ancs = ancestors else ancs = self.class.ancestors end ancs.reverse.inject({}){|s,v| s.merge(v.trait)}.merge(trait) end |