Class: ProcMethodFactory
- Defined in:
- lib/white_gold/convention/proc_method_factory.rb
Instance Method Summary collapse
-
#initialize(source) ⇒ ProcMethodFactory
constructor
A new instance of ProcMethodFactory.
- #method_missing(name, *curry) ⇒ Object
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(source) ⇒ ProcMethodFactory
Returns a new instance of ProcMethodFactory.
2 3 4 |
# File 'lib/white_gold/convention/proc_method_factory.rb', line 2 def initialize source @source = source end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *curry) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/white_gold/convention/proc_method_factory.rb', line 6 def method_missing name, *curry proc do |*a, **na, &b| method = @source.method name arity = method.arity a = [*curry, *a] if arity >= 0 @source.send(name, *a[...arity], **na, &b) else @source.send(name, *a, **na, &b) end end end |
Instance Method Details
#respond_to?(name) ⇒ Boolean
19 20 21 |
# File 'lib/white_gold/convention/proc_method_factory.rb', line 19 def respond_to? name @source.respond_to? name end |