Class: Soroban::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/soroban/functions.rb

Class Method Summary collapse

Class Method Details

.allObject

Return an array of all defined functions.


17
18
19
# File 'lib/soroban/functions.rb', line 17

def self.all
  @@_functions.keys.map(&:to_s).to_a.sort
end

.call(sheet, name, *args) ⇒ Object

Call the named function within the context of the specified sheet, supplying some number of arguments (which is a property of the function, and therefore given as a splat here).


24
25
26
27
28
# File 'lib/soroban/functions.rb', line 24

def self.call(sheet, name, *args)
  callback = @@_functions[name.to_s.upcase.to_sym]
  raise Soroban::UndefinedError, "No such function '#{name}'" if callback.nil?
  sheet.instance_exec(*args, &callback)
end

.define(function_hash) ⇒ Object

Define one or more functions by passing in a hash mapping function name to the lambda that computes the function's value.


9
10
11
12
13
14
# File 'lib/soroban/functions.rb', line 9

def self.define(function_hash)
  @@_functions ||= {}
  function_hash.each do |name, callback|
    @@_functions[name.to_s.upcase.to_sym] = callback
  end
end