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.



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cel/ast/elements.rb', line 122

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.



120
121
122
# File 'lib/cel/ast/elements.rb', line 120

def type
  @type
end

#typesObject (readonly)

Returns the value of attribute types.



120
121
122
# File 'lib/cel/ast/elements.rb', line 120

def types
  @types
end

Instance Method Details

#call(*args) ⇒ Object



136
137
138
# File 'lib/cel/ast/elements.rb', line 136

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