Class: CSVPlusPlus::Entities::Function
- Inherits:
-
EntityWithArguments
- Object
- Entity
- EntityWithArguments
- CSVPlusPlus::Entities::Function
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/entities/function.rb
Overview
A function definition
Instance Attribute Summary collapse
-
#body ⇒ Entity
readonly
The body of the function.
Attributes inherited from EntityWithArguments
Attributes inherited from Entity
Instance Method Summary collapse
- #==(other) ⇒ ::T::Boolean
- #evaluate(runtime) ⇒ ::String
-
#initialize(id, arguments, body) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(id, arguments, body) ⇒ Function
Returns a new instance of Function.
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
#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 |
Instance Method Details
#==(other) ⇒ ::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
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 |