Class: MiniRuby::AST::BreakExpressionNode

Inherits:
ExpressionNode show all
Defined in:
lib/miniruby/ast.rb

Overview

Represents a break like ‘break`, `break 1 + 5 * a`

Instance Attribute Summary collapse

Attributes inherited from Node

#span

Instance Method Summary collapse

Constructor Details

#initialize(value: nil, span: Span::ZERO) ⇒ BreakExpressionNode

: (?value: ExpressionNode?, ?span: Span) -> void



466
467
468
469
# File 'lib/miniruby/ast.rb', line 466

def initialize(value: nil, span: Span::ZERO)
  @span = span
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

: ExpressionNode?



463
464
465
# File 'lib/miniruby/ast.rb', line 463

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object

: (Object other) -> bool



472
473
474
475
476
# File 'lib/miniruby/ast.rb', line 472

def ==(other)
  return false unless other.is_a?(BreakExpressionNode)

  @value == other.value
end

#inspect(indent = 0) ⇒ Object

: (?Integer indent) -> String



490
491
492
493
494
495
496
497
# File 'lib/miniruby/ast.rb', line 490

def inspect(indent = 0)
  buff = String.new
  buff << "#{INDENT_UNIT * indent}(break"
  buff << " #{@value.inspect}" if @value
  buff << ')'

  buff
end

#to_s(indent = 0) ⇒ Object

: (?Integer indent) -> String



480
481
482
483
484
485
486
# File 'lib/miniruby/ast.rb', line 480

def to_s(indent = 0)
  buff = String.new
  buff << "#{INDENT_UNIT * indent}break"
  buff << " #{@value}" if @value

  buff
end