Class: MiniRuby::AST::AssignmentExpressionNode
- Inherits:
-
ExpressionNode
- Object
- Node
- ExpressionNode
- MiniRuby::AST::AssignmentExpressionNode
- Defined in:
- lib/miniruby/ast.rb
Overview
Represents an assignment expression like ‘a = 5`, `b = 2 + 5 * 5`
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
: ExpressionNode.
-
#value ⇒ Object
readonly
: ExpressionNode.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object other) -> bool.
-
#initialize(target:, value:, span: Span::ZERO) ⇒ AssignmentExpressionNode
constructor
: (target: ExpressionNode, value: ExpressionNode, ?span: Span) -> void.
-
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String.
-
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String.
Constructor Details
#initialize(target:, value:, span: Span::ZERO) ⇒ AssignmentExpressionNode
: (target: ExpressionNode, value: ExpressionNode, ?span: Span) -> void
343 344 345 346 347 |
# File 'lib/miniruby/ast.rb', line 343 def initialize(target:, value:, span: Span::ZERO) @span = span @target = target @value = value end |
Instance Attribute Details
#target ⇒ Object (readonly)
: ExpressionNode
337 338 339 |
# File 'lib/miniruby/ast.rb', line 337 def target @target end |
#value ⇒ Object (readonly)
: ExpressionNode
340 341 342 |
# File 'lib/miniruby/ast.rb', line 340 def value @value end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
350 351 352 353 354 355 |
# File 'lib/miniruby/ast.rb', line 350 def ==(other) return false unless other.is_a?(AssignmentExpressionNode) @target == other.target && @value == other.value end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
365 366 367 368 369 370 371 372 373 374 |
# File 'lib/miniruby/ast.rb', line 365 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(assignment" buff << "\n" << @target.inspect(indent + 1) buff << "\n" << @value.inspect(indent + 1) buff << ')' buff end |
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String
359 360 361 |
# File 'lib/miniruby/ast.rb', line 359 def to_s(indent = 0) "#{INDENT_UNIT * indent}#{@target} = #{@value}" end |