Class: Lab42::Console::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/lab42/console/function.rb

Constant Summary collapse

Error =
Class.new RuntimeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#functionsObject (readonly)

Returns the value of attribute functions.



6
7
8
# File 'lib/lab42/console/function.rb', line 6

def functions
  @functions
end

#sourcesObject (readonly)

Returns the value of attribute sources.



6
7
8
# File 'lib/lab42/console/function.rb', line 6

def sources
  @sources
end

Instance Method Details

#add(*args, &blk) ⇒ Object



8
9
10
11
12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
# File 'lib/lab42/console/function.rb', line 18

def call(element)
  functions
    .inject(element) do |acc, fn| 
      fn.(acc) 
    end
end

#to_procObject



25
26
27
# File 'lib/lab42/console/function.rb', line 25

def to_proc
  -> x { call(x) }
end