Class: Cel::Function

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Function.



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cel/ast/elements.rb', line 111

def initialize(*types, 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
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



109
110
111
# File 'lib/cel/ast/elements.rb', line 109

def type
  @type
end

#typesObject (readonly)

Returns the value of attribute types.



109
110
111
# File 'lib/cel/ast/elements.rb', line 109

def types
  @types
end

Instance Method Details

#call(*args) ⇒ Object



125
126
127
# File 'lib/cel/ast/elements.rb', line 125

def call(*args)
  Literal.to_cel_type(@func.call(*args))
end