Class: CEL::Context

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__native_newObject



15
# File 'lib/cel.rb', line 15

alias_method :__native_new, :new

.build(empty: false, **variables) {|ctx| ... } ⇒ Object

Yields:

  • (ctx)


21
22
23
24
25
26
# File 'lib/cel.rb', line 21

def build(empty: false, **variables)
  ctx = new(empty)
  variables.each { |k, v| ctx.add_variable(k.to_s, v) }
  yield(ctx) if block_given?
  ctx
end

.new(empty = false) ⇒ Object



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

def new(empty = false)
  __native_new(!!empty)
end

Instance Method Details

#define_function(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/cel.rb', line 29

def define_function(name, &block)
  raise ArgumentError, "block required" unless block

  add_function(name.to_s, block)
end