Module: Traitee::Trait

Extended by:
Forwardable
Includes:
Merger
Defined in:
lib/traitee/trait.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Merger

#merge

Class Method Details

.subject_composition(*params, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/traitee/trait.rb', line 37

def self.subject_composition(*params, &block)
  Class.new do
    extend Trait
    merge(*params) unless params.empty?
    serves(&block) if block
  end
end

Instance Method Details

#[]Object



9
# File 'lib/traitee/trait.rb', line 9

alias_method :[], :methods

#dictObject



17
18
19
# File 'lib/traitee/trait.rb', line 17

def dict
  @dict ||= Dict.new
end

#methods(options = {}) ⇒ Object

usable methods



22
23
24
25
# File 'lib/traitee/trait.rb', line 22

def methods(options = {})
  served_from(this, *this.instance_methods)
  dict.methods_hash(options)
end

#served_from(trait_module, *methods) ⇒ Object

store Module where method is defined (trait) and actual method name



33
34
35
# File 'lib/traitee/trait.rb', line 33

def served_from(trait_module, *methods)
  methods.each { |method_name| dict << [trait_module, method_name] }
end

#serves(&method_def) ⇒ Object

helper for actual method definitions



28
29
30
# File 'lib/traitee/trait.rb', line 28

def serves(&method_def)
  this.module_eval(&method_def)
end

#thisObject



13
14
15
# File 'lib/traitee/trait.rb', line 13

def this
  @this ||= Module.new
end