Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/cube/traits.rb

Instance Method Summary collapse

Instance Method Details

#with_trait(trait, rename: {}, suppress: []) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cube/traits.rb', line 50

def with_trait(trait, rename: {}, suppress: [])
  unless trait.is_a? Cube::Trait
    raise ArgumentError, "#{trait} is not an Cube::Trait"
  end
  cls = clone
  cls.instance_variable_set(:@__trait_allow_include, true)
  cls.instance_variable_set(:@__trait_cloned_from, self)
  raise ArgumentError, "aliases must be a Hash" unless rename.is_a?(Hash)
  raise ArgumentError, "supresses must be a Array" unless suppress.is_a?(Array)

  al_trait = trait_with_resolutions(trait, rename, suppress)
  al_trait.instance_variable_set(:@__interface_runtime_check, false)
  cls.include(al_trait)
  cls
end