Class: Cel::Function

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types, label: nil, return_type: nil, &func) ⇒ Function

Returns a new instance of Function.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cel/ast/elements/function.rb', line 7

def initialize(*types, label: nil, return_type: nil, &func)
  unless func.nil?
    types = Array.new(func.arity) { TYPES[:any] } if types.empty?
    raise(Error, "number of arg types does not match number of yielded args") unless types.size == func.arity
  end
  @types = types.map { |typ| typ.is_a?(Type) ? typ : TYPES[typ] }
  @type = if return_type.nil?
    TYPES[:any]
  else
    return_type.is_a?(Type) ? return_type : TYPES[return_type]
  end
  @func = func
  @label = label
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/cel/ast/elements/function.rb', line 5

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/cel/ast/elements/function.rb', line 5

def type
  @type
end

#typesObject (readonly)

Returns the value of attribute types.



5
6
7
# File 'lib/cel/ast/elements/function.rb', line 5

def types
  @types
end

Instance Method Details

#call(*args) ⇒ Object



22
23
24
25
26
# File 'lib/cel/ast/elements/function.rb', line 22

def call(*args)
  result = @func.call(*args)

  @type.convert(result)
end