Fn
is the class of all functions. An object of class Fn
can be called with arguments. The number of arguments must match the arity of the function, i.e. the number of parameters.
Static Methods
indirect_call(fn, args)
Call function fn
with the arguments in the array args
. fn
must be an instance of Fn
and not a callable.
def hello(name) {
return "Hello " + name
}
IO.println(Fn.indirect_call(hello, ["World"])) #> Hello World
new(function)
Create a new function thanks to function
. function
must be a block argument. All this function do is return its argument.
def identity = Fn.new {|a| a }
IO.println(identity(42)) #> 42