Module: ToProcInterface::Delegations Private
- Included in:
- Mixin, Singleton::ClassMethods
- Defined in:
- lib/to_proc_interface.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Mixin module with delegations to #to_proc method to mimic Proc behavior.
Constant Summary collapse
- @@proc_methods =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
[]
- @@args_by_arity =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
[ "", "arg", "*args, **opts, &block" ].freeze
Class Method Summary collapse
-
.delegate_to_proc(name, arity: nil) ⇒ Symbol
private
Delegated method name.
- .proc_methods ⇒ Array<Symbol> private
Instance Method Summary collapse
- #:<<(...) ⇒ Object
- #:>>(...) ⇒ Object
- #:[](...) ⇒ Object
- #arity(...) ⇒ Object
- #binding(...) ⇒ Object
- #curry(...) ⇒ Object
- #lambda?(...) ⇒ Object
- #parameters(...) ⇒ Object
- #ruby2_keywords(...) ⇒ Object
- #source_location(...) ⇒ Object
- #yield(...) ⇒ Object
Class Method Details
.delegate_to_proc(name, arity: nil) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns delegated method name.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/to_proc_interface.rb', line 44 def delegate_to_proc(name, arity: nil) name = name.to_sym arity ||= Proc.instance_method(name).arity args = @@args_by_arity[arity.clamp(-1, 1)] class_eval(<<~RUBY, __FILE__, __LINE__ + 1).tap { proc_methods << _1 } def #{name}(#{args}) to_proc.#{name}(#{args}) end RUBY end |
.proc_methods ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/to_proc_interface.rb', line 21 def proc_methods @@proc_methods end |
Instance Method Details
#:<<(...) ⇒ Object
64 |
# File 'lib/to_proc_interface.rb', line 64 delegate_to_proc :<<, arity: 1 |
#:>>(...) ⇒ Object
65 |
# File 'lib/to_proc_interface.rb', line 65 delegate_to_proc :>>, arity: 1 |
#:[](...) ⇒ Object
63 |
# File 'lib/to_proc_interface.rb', line 63 delegate_to_proc :[], arity: -1 |
#arity(...) ⇒ Object
58 |
# File 'lib/to_proc_interface.rb', line 58 delegate_to_proc :arity, arity: 0 |
#binding(...) ⇒ Object
60 |
# File 'lib/to_proc_interface.rb', line 60 delegate_to_proc :binding, arity: 0 |
#curry(...) ⇒ Object
61 |
# File 'lib/to_proc_interface.rb', line 61 delegate_to_proc :curry, arity: -1 |
#lambda?(...) ⇒ Object
59 |
# File 'lib/to_proc_interface.rb', line 59 delegate_to_proc :lambda?, arity: 0 |
#parameters(...) ⇒ Object
57 |
# File 'lib/to_proc_interface.rb', line 57 delegate_to_proc :parameters, arity: 0 |
#ruby2_keywords(...) ⇒ Object
67 |
# File 'lib/to_proc_interface.rb', line 67 delegate_to_proc :ruby2_keywords |
#source_location(...) ⇒ Object
66 |
# File 'lib/to_proc_interface.rb', line 66 delegate_to_proc :source_location |
#yield(...) ⇒ Object
62 |
# File 'lib/to_proc_interface.rb', line 62 delegate_to_proc :yield, arity: -1 |