Module: Traitorous::ClassMethods

Defined in:
lib/traitorous.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#traitsHashWithIndifferntAccess

There’s no reason you can’t manually alter the .traits hash, but be aware of the potential consequences upon your data when doing so.

Returns:

  • (HashWithIndifferntAccess)


38
39
40
# File 'lib/traitorous.rb', line 38

def traits
  @traits
end

Instance Method Details

#trait(attr_name, converter = Convert.noop) ⇒ Object

Parameters:

  • attr_name (Symbol, String)

    name of the attribute, follows normal method name rules

  • converter (Traitorous::Converter, #do_import, #do_export) (defaults to: Convert.noop)

    the converter this trait will use during import and export operations. A converter must implement #do_import(data) and #do_export(data) but can otherwise be any object or module.

    defaults to Traitorous::Converter::DEFAULT



48
49
50
51
52
# File 'lib/traitorous.rb', line 48

def trait(attr_name, converter = Convert.noop)
  self.traits            ||= HASH.new
  self.traits[attr_name.intern] = converter
  attr_accessor attr_name
end