Class: CSVPlusPlus::Entities::Function

Inherits:
EntityWithArguments show all
Extended by:
T::Sig
Includes:
HasIdentifier
Defined in:
lib/csv_plus_plus/entities/function.rb

Overview

A function definition

Constant Summary collapse

ArgumentsType =
type_member { { fixed: ::Symbol } }

Instance Attribute Summary collapse

Attributes inherited from EntityWithArguments

#arguments

Instance Method Summary collapse

Methods included from HasIdentifier

#identifier

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)


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

def initialize(id, arguments, body)
  super(arguments: arguments.map(&:to_sym))

  @body = ::T.let(body, ::CSVPlusPlus::Entities::Entity)
  @id = ::T.let(identifier(id), ::Symbol)
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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

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

Parameters:

Returns:

  • (::T::Boolean)


46
47
48
49
50
51
52
53
# File 'lib/csv_plus_plus/entities/function.rb', line 46

def ==(other)
  case other
  when self.class
    @body == other.body && super
  else
    false
  end
end

#evaluate(position) ⇒ String

Parameters:

  • position (Position)

Returns:



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

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