Class: CSVPlusPlus::Language::Entities::Function

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

Overview

A function definition

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

Create a function

Parameters:

  • id (Symbool, String)

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

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


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

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::Language::Entities::Entity

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

Instance Method Details

#==(other) ⇒ Object



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

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

#to_sObject

to_s



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

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