Class: Traitor::Trait
- Inherits:
-
Object
- Object
- Traitor::Trait
- Defined in:
- lib/traitor/trait.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(host, m, *args, &block) ⇒ Object
- #implements?(m) ⇒ Boolean
-
#initialize(&block) ⇒ Trait
constructor
A new instance of Trait.
- #trait_methods ⇒ Object
Constructor Details
#initialize(&block) ⇒ Trait
Returns a new instance of Trait.
5 6 7 8 |
# File 'lib/traitor/trait.rb', line 5 def initialize(&block) @module_block = block @container = Module.new(&block) end |
Class Method Details
.check_conflict(host_class) ⇒ Object
30 31 32 |
# File 'lib/traitor/trait.rb', line 30 def self.check_conflict(host_class) ConflictCheck.check(host_class) end |
Instance Method Details
#call(host, m, *args, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/traitor/trait.rb', line 18 def call(host, m, *args, &block) = class << host; self; end blk = @module_block refinement = Module.new do refine , &blk end host.send :using, refinement host.send m, *args, &block end |
#implements?(m) ⇒ Boolean
14 15 16 |
# File 'lib/traitor/trait.rb', line 14 def implements?(m) trait_methods.include?(m) end |
#trait_methods ⇒ Object
10 11 12 |
# File 'lib/traitor/trait.rb', line 10 def trait_methods @container.instance_methods(false) end |