Class: CSVPlusPlus::Entities::Function

Inherits:
EntityWithArguments show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/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

Constructor Details

#initialize(id, arguments, body) ⇒ Function

Returns a new instance of Function.

Parameters:

  • id (Symbol)

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

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


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

def initialize(id, arguments, body)
  super(::CSVPlusPlus::Entities::Type::Function, id:, arguments: arguments.map(&:to_sym))

  @body = ::T.let(body, ::CSVPlusPlus::Entities::Entity)
end

Instance Attribute Details

#bodyEntity (readonly)

The body of the function. body can contain variable references from @arguments

Returns:

  • (Entity)

    the current value of body



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

def body
  @body
end

Instance Method Details

#==(other) ⇒ ::T::Boolean

Parameters:

Returns:

  • (::T::Boolean)


38
39
40
41
42
# File 'lib/csv_plus_plus/entities/function.rb', line 38

def ==(other)
  return false unless super

  other.is_a?(self.class) && @body == other.body
end

#evaluate(runtime) ⇒ ::String

Parameters:

Returns:

  • (::String)


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

def evaluate(runtime)
  "def #{@id.to_s.upcase}(#{arguments.map(&:to_s).join(', ')}) #{@body.evaluate(runtime)}"
end