Method: Object#trait
- Defined in:
- lib/m4dbi/traits.rb
#trait(hash = nil) ⇒ Object
Adds a method to Object to annotate your objects with certain traits. It’s basically a simple Hash that takes the current object as key
Example:
class Foo
trait :instance => false
def initialize
trait :instance => true
end
end
Foo.trait[:instance]
# false
foo = Foo.new
foo.trait[:instance]
# true
32 33 34 35 36 37 38 |
# File 'lib/m4dbi/traits.rb', line 32 def trait hash = nil if hash Traits[self].merge! hash else Traits[self] end end |