require 'traits'
#
# a hash argument can be used to specify default values
#
class C
  has 'a' => 4, :b => 2 
end

o = C::new
print o.a, o.b, "\n"

#
# and these traits are smartly inherited
#
class K < C; end

o = K::new
o.a = 40
p( o.a + o.b ) # note that we pick up a default b from C class here since it
               # has not been set

o.a = 42
o.b = nil
p( o.b || o.a ) # but not here since we've explicitly set it to nil

#
# if a block is specifed as the default the initialization of the default value
# is deferred until needed which makes for quite natural trait definitions.  the
# block is passed 'self' so references to the current object can be made. (if
# this were not done 'self' in the block would be bound to the class!)
#

class C
  class << self
    has('classname'){ name.upcase }
  end

  has('classname'){ self.class.classname.downcase }
end

class B < C; end

o = C::new
p C::classname
p o.classname

o = B::new
p B::classname
p o.classname
