Class: Cel::Function
- Inherits:
-
Object
- Object
- Cel::Function
- Defined in:
- lib/cel/ast/elements/function.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(*types, label: nil, return_type: nil, &func) ⇒ Function
constructor
A new instance of Function.
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
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/cel/ast/elements/function.rb', line 5 def label @label end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/cel/ast/elements/function.rb', line 5 def type @type end |
#types ⇒ Object (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 |