Class: Method
Instance Method Summary collapse
-
#apply(*args) ⇒ Object, Proc
Curries this Method and partially applies parameters.
-
#to_iter(*args) ⇒ Iterator
Creates an Iterator object, which is a subclass of Enumerator that recursively invokes this method on an object.
Instance Method Details
#apply(*args) ⇒ Object, Proc
Method#curry is in stdlib since Ruby 2.2. apply is shorthand
for curry.call(...).
Curries this Method and partially applies parameters. If a sufficient number of arguments are supplied, it passes the supplied arguments to the original proc and returns the result. Otherwise, returns another curried proc that takes the rest of arguments.
58 59 60 61 |
# File 'lib/mug/apply.rb', line 58 def apply(*args) n = arity < 0 ? -arity - 1 : arity curry(n).call(*args) end |
#to_iter(*args) ⇒ Iterator
Creates an Iterator object, which is a subclass of Enumerator that recursively invokes this method on an object.
Initially the receiving object is the object on which this method is defined. After each iteration, the receiving object is replaced with the result of the previous iteration.
21 22 23 24 25 |
# File 'lib/mug/iterator/method.rb', line 21 def to_iter *args Iterator.new(receiver) do |o| o.send(name, *args) end end |