Class: CSVPlusPlus::Entities::FunctionCall

Inherits:
EntityWithArguments show all
Defined in:
lib/csv_plus_plus/entities/function_call.rb

Overview

A function call

Instance Attribute Summary collapse

Attributes inherited from EntityWithArguments

#arguments

Attributes inherited from Entity

#id, #type

Instance Method Summary collapse

Methods inherited from Entity

#method_missing, #respond_to_missing?

Constructor Details

#initialize(id, arguments, infix: false) ⇒ FunctionCall

Returns a new instance of FunctionCall.

Parameters:

  • id (String)

    The name of the function

  • arguments (Array<Entity>)

    The arguments to the function

  • infix (boolean) (defaults to: false)

    Whether the function is infix



14
15
16
17
18
# File 'lib/csv_plus_plus/entities/function_call.rb', line 14

def initialize(id, arguments, infix: false)
  super(:function_call, id:, arguments:)

  @infix = infix
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CSVPlusPlus::Entities::Entity

Instance Attribute Details

#infixboolean (readonly)

Whether or not this function call is infix (X * Y, A + B, etc)

Returns:

  • (boolean)

    the current value of infix



8
9
10
# File 'lib/csv_plus_plus/entities/function_call.rb', line 8

def infix
  @infix
end

Instance Method Details

#==(other) ⇒ boolean

Returns:

  • (boolean)


30
31
32
# File 'lib/csv_plus_plus/entities/function_call.rb', line 30

def ==(other)
  super && @id == other.id
end

#to_sString

Returns:



21
22
23
24
25
26
27
# File 'lib/csv_plus_plus/entities/function_call.rb', line 21

def to_s
  if @infix
    "(#{arguments.join(" #{@id} ")})"
  else
    "#{@id.to_s.upcase}(#{arguments_to_s})"
  end
end