Class: Dry::Types::Constructor::Function Private
- Inherits:
-
Object
- Object
- Dry::Types::Constructor::Function
- Defined in:
- lib/dry/types/constructor/function.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Function is used internally by Constructor types
Direct Known Subclasses
Defined Under Namespace
Classes: MethodCall, Safe, Wrapper
Instance Attribute Summary collapse
- #fn ⇒ Object readonly private
Class Method Summary collapse
-
.[](fn) ⇒ Function
private
Choose or build specialized invokation code for a callable.
- .yields_block?(fn) ⇒ Boolean private
Instance Method Summary collapse
- #<<(other) ⇒ Function private
- #>>(other) ⇒ Function private
- #arity ⇒ Integer private
- #call(input) ⇒ Object (also: #[]) private
-
#initialize(fn) ⇒ Function
constructor
private
A new instance of Function.
- #to_ast ⇒ Array private
- #wrapper? ⇒ Boolean private
Constructor Details
#initialize(fn) ⇒ Function
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 a new instance of Function.
167 168 169 |
# File 'lib/dry/types/constructor/function.rb', line 167 def initialize(fn) @fn = fn end |
Instance Attribute Details
#fn ⇒ Object (readonly)
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.
165 166 167 |
# File 'lib/dry/types/constructor/function.rb', line 165 def fn @fn end |
Class Method Details
.[](fn) ⇒ Function
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.
Choose or build specialized invokation code for a callable
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/dry/types/constructor/function.rb', line 135 def self.[](fn) raise ::ArgumentError, "Missing constructor block" if fn.nil? if fn.is_a?(Function) fn elsif fn.respond_to?(:arity) && fn.arity.equal?(2) Wrapper.new(fn) elsif fn.is_a?(::Method) MethodCall[fn, yields_block?(fn)] elsif yields_block?(fn) new(fn) else Safe.new(fn) end end |
.yields_block?(fn) ⇒ Boolean
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.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dry/types/constructor/function.rb', line 152 def self.yields_block?(fn) *, (last_arg,) = if fn.respond_to?(:parameters) fn.parameters else fn.method(:call).parameters end last_arg.equal?(:block) end |
Instance Method Details
#<<(other) ⇒ Function
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.
196 197 198 199 |
# File 'lib/dry/types/constructor/function.rb', line 196 def <<(other) f = Function[other] Function[-> x, &b { self.(f.(x, &b), &b) }] end |
#>>(other) ⇒ Function
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.
190 191 192 193 |
# File 'lib/dry/types/constructor/function.rb', line 190 def >>(other) f = Function[other] Function[-> x, &b { f.(self.(x, &b), &b) }] end |
#arity ⇒ Integer
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.
176 |
# File 'lib/dry/types/constructor/function.rb', line 176 def arity = 1 |
#call(input) ⇒ Object Also known as: []
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.
172 |
# File 'lib/dry/types/constructor/function.rb', line 172 def call(input, &) = @fn.(input, &) |
#to_ast ⇒ Array
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.
181 182 183 184 185 186 187 |
# File 'lib/dry/types/constructor/function.rb', line 181 def to_ast if fn.is_a?(::Proc) [:id, FnContainer.register(fn)] else [:callable, fn] end end |
#wrapper? ⇒ Boolean
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.
178 |
# File 'lib/dry/types/constructor/function.rb', line 178 def wrapper? = arity.equal?(2) |