require 'traits'
#
# two kinds of in-place modifications are supported : casting and munging. 
# casting is a hook that requires either a proc or the name of a method that
# will be used to convert the objects type.  munging is similar execpt the
# method is called on the object itself.  like all hooks, lists may be provided
# instead of a single argument
#
# you'll notice that the hooks and methods defined here are not strictly needed,
# but are for illustration purposes only.  note that all hooks operate in the
# context of self - they have access to instance vars, etc., like instance_eval
#

class C
  INT = lambda{|i| int i}
  def int i
    Integer i
  end
  trait 'a', 'cast' => 'int'
  trait 'b', 'cast' => INT 
  trait 'c', 'munge' => 'to_i' 
  trait 'd', 'cast' => 'Integer' 
  trait 'e', 'munge' => %w( to_i abs )
end

c = C::new

c.a = '42'
p c.a
c.b = '42'
p c.b
c.c = '42'
p c.c
c.d = '42'
p c.d
c.e = '-42'
p c.e
