class Lab42::Console::Function
Constants
- Error
Attributes
functions[R]
sources[R]
Public Class Methods
new(*args, &blk)
click to toggle source
# File lib/lab42/console/function.rb, line 31 def initialize(*args, &blk) @functions = [] @sources = [] add(*args, &blk) end
Public Instance Methods
add(*args, &blk)
click to toggle source
# File lib/lab42/console/function.rb, line 8 def add(*args, &blk) if args.empty? _add_blk(blk) else raise Error, "must not provide literal and block behaviour at the same time" if blk _add_args(args) end self end
call(element)
click to toggle source
# File lib/lab42/console/function.rb, line 18 def call(element) functions .inject(element) do |acc, fn| fn.(acc) end end
to_proc()
click to toggle source
# File lib/lab42/console/function.rb, line 25 def to_proc -> x { call(x) } end
Private Instance Methods
_add_args(args)
click to toggle source
# File lib/lab42/console/function.rb, line 37 def _add_args(args) functions << _add_args_fn(args) end
_add_args_fn(args)
click to toggle source
# File lib/lab42/console/function.rb, line 41 def _add_args_fn(args) sources << "send #{args.join(", ")}" -> reciever do reciever.send(*args) rescue nil end end
_add_blk(blk)
click to toggle source
# File lib/lab42/console/function.rb, line 50 def _add_blk(blk) sources << blk.to_s functions << blk end