Module: Detach::Types
- Defined in:
- lib/detach.rb
Overview
The Detach::Types module is inserted as a parent of the class which includes the Detach mixin. This module handles inspection and aliasing of instance methods as they are added.
Detach::Types does not need to be extended directly.
Instance Method Summary collapse
-
#[](*types) ⇒ Object
:stopdoc:.
- #method_added(name) ⇒ Object
-
#taking ⇒ Object
Decorator method for defining argument signature.
Instance Method Details
#[](*types) ⇒ Object
:stopdoc:
87 88 89 |
# File 'lib/detach.rb', line 87 def [](*types) @@types = types.flatten end |
#method_added(name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/detach.rb', line 90 def method_added(name) return unless @@types # query the parameter info for the method just added p = instance_method(name).parameters.map &:first raise ArgumentError.new('type and parameter mismatch') unless p.size == @@types.size # encode our defined types with parameter info into a new name and remove the original n = (name.to_s + '(' + p.zip(@@types).collect {|p,t| "#{p}-#{t}" }.join(',') + ')').to_sym @@types = nil alias_method n, name unless method_defined?(n) define_method(name) {|*args, &block| method_missing(name, *args, &block)} end |
#taking ⇒ Object
Decorator method for defining argument signature.
Example:
taking['String']
def foo(a)
end
83 84 85 |
# File 'lib/detach.rb', line 83 def taking self end |