Class: Cel::Invoke

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Invoke.



44
45
46
47
48
# File 'lib/cel/ast/elements.rb', line 44

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.



42
43
44
# File 'lib/cel/ast/elements.rb', line 42

def args
  @args
end

#funcObject (readonly)

Returns the value of attribute func.



42
43
44
# File 'lib/cel/ast/elements.rb', line 42

def func
  @func
end

#varObject (readonly)

Returns the value of attribute var.



42
43
44
# File 'lib/cel/ast/elements.rb', line 42

def var
  @var
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
53
54
55
# File 'lib/cel/ast/elements.rb', line 50

def ==(other)
  super || (
    other.respond_to?(:to_ary) &&
    [@var, @func, @args].compact == other
  )
end

#to_sObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cel/ast/elements.rb', line 57

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