Class: CSVPlusPlus::Entities::Function
- Inherits:
-
EntityWithArguments
- Object
- Entity
- EntityWithArguments
- CSVPlusPlus::Entities::Function
- 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
-
#body ⇒ Entity
readonly
The body of the function.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from EntityWithArguments
Instance Method Summary collapse
- #==(other) ⇒ ::T::Boolean
- #evaluate(position) ⇒ String
-
#initialize(id, arguments, body) ⇒ Function
constructor
A new instance of Function.
Methods included from HasIdentifier
Constructor Details
#initialize(id, arguments, body) ⇒ Function
Returns a new instance of Function.
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
#body ⇒ Entity (readonly)
The body of the function. body
can contain variable references from @arguments
10 11 12 |
# File 'lib/csv_plus_plus/entities/function.rb', line 10 def body @body end |
#id ⇒ Object (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
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
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 |