Class: Cel::Invoke

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(func:, var: nil, args: nil) ⇒ Invoke

Returns a new instance of Invoke.



89
90
91
92
93
# File 'lib/cel/ast/elements.rb', line 89

def initialize(func:, var: nil, args: nil)
  @var = var
  @func = func.to_sym
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



83
84
85
# File 'lib/cel/ast/elements.rb', line 83

def args
  @args
end

#funcObject (readonly)

Returns the value of attribute func.



83
84
85
# File 'lib/cel/ast/elements.rb', line 83

def func
  @func
end

#varObject (readonly)

Returns the value of attribute var.



83
84
85
# File 'lib/cel/ast/elements.rb', line 83

def var
  @var
end

Class Method Details

.new(func:, var: nil, args: nil) ⇒ Object



85
86
87
# File 'lib/cel/ast/elements.rb', line 85

def self.new(func:, var: nil, args: nil)
  Protobuf.try_invoke_from(var, func, args) || super
end

Instance Method Details

#==(other) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/cel/ast/elements.rb', line 95

def ==(other)
  case other
  when Invoke
    @var == other.var && @func == other.func && @args == other.args
  when Array
    [@var, @func, @args].compact == other
  else
    super
  end
end

#to_sObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cel/ast/elements.rb', line 106

def to_s
  if var
    if func == :[]
      "#{var}[#{args}]"
    else
      "#{var}.#{func}#{"(#{args.map(&:to_s).join(", ")})" if args}"
    end
  else
    "#{func}#{"(#{args.map(&:to_s).join(", ")})" if args}"
  end
end