Module: Traitee::Trait
Class Method Summary collapse
Instance Method Summary collapse
- #[] ⇒ Object
- #dict ⇒ Object
-
#methods(options = {}) ⇒ Object
usable methods.
-
#served_from(trait_module, *methods) ⇒ Object
store Module where method is defined (trait) and actual method name.
-
#serves(&method_def) ⇒ Object
helper for actual method definitions.
- #this ⇒ Object
Methods included from Merger
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 |
#dict ⇒ Object
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( = {}) served_from(this, *this.instance_methods) dict.methods_hash() 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 |
#this ⇒ Object
13 14 15 |
# File 'lib/traitee/trait.rb', line 13 def this @this ||= Module.new end |