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, &block) ⇒ 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.
173 174 175 |
# File 'lib/dry/types/constructor/function.rb', line 173 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.
171 172 173 |
# File 'lib/dry/types/constructor/function.rb', line 171 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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/dry/types/constructor/function.rb', line 141 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.
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/dry/types/constructor/function.rb', line 158 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.
208 209 210 211 |
# File 'lib/dry/types/constructor/function.rb', line 208 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.
202 203 204 205 |
# File 'lib/dry/types/constructor/function.rb', line 202 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.
184 185 186 |
# File 'lib/dry/types/constructor/function.rb', line 184 def arity 1 end |
#call(input, &block) ⇒ 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.
178 179 180 |
# File 'lib/dry/types/constructor/function.rb', line 178 def call(input, &block) @fn.(input, &block) end |
#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.
193 194 195 196 197 198 199 |
# File 'lib/dry/types/constructor/function.rb', line 193 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.
188 189 190 |
# File 'lib/dry/types/constructor/function.rb', line 188 def wrapper? arity.equal?(2) end |