Class: CSVPlusPlus::Entities::Function

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

Overview

A function definition

from @arguments

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, body) ⇒ Function

Returns a new instance of Function.

Parameters:

  • id (Symbool, String)

    the name of the function - what it will be callable by

  • arguments (Array<Symbol>)
  • body (Entity)


17
18
19
20
# File 'lib/csv_plus_plus/entities/function.rb', line 17

def initialize(id, arguments, body)
  super(:function, id:, arguments: arguments.map(&:to_sym))
  @body = body
end

Dynamic Method Handling

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

Instance Attribute Details

#bodyEntity (readonly)

The body of the function. body can contain variable references

Returns:

  • (Entity)

    the current value of body



11
12
13
# File 'lib/csv_plus_plus/entities/function.rb', line 11

def body
  @body
end

Instance Method Details

#==(other) ⇒ boolean

Returns:

  • (boolean)


28
29
30
# File 'lib/csv_plus_plus/entities/function.rb', line 28

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

#to_sString

Returns:



23
24
25
# File 'lib/csv_plus_plus/entities/function.rb', line 23

def to_s
  "def #{@id.to_s.upcase}(#{arguments_to_s}) #{@body}"
end