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.



78
79
80
81
82
# File 'lib/cel/ast/elements.rb', line 78

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.



72
73
74
# File 'lib/cel/ast/elements.rb', line 72

def args
  @args
end

#funcObject (readonly)

Returns the value of attribute func.



72
73
74
# File 'lib/cel/ast/elements.rb', line 72

def func
  @func
end

#varObject (readonly)

Returns the value of attribute var.



72
73
74
# File 'lib/cel/ast/elements.rb', line 72

def var
  @var
end

Class Method Details

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



74
75
76
# File 'lib/cel/ast/elements.rb', line 74

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

Instance Method Details

#==(other) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/cel/ast/elements.rb', line 84

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



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

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