Class: MiniRuby::AST::ExpressionStatementNode

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

Overview

Represents a statement with an expression like ‘2 + 3 - 5;`

Instance Attribute Summary collapse

Attributes inherited from Node

#span

Instance Method Summary collapse

Constructor Details

#initialize(expression:, span: Span::ZERO) ⇒ ExpressionStatementNode

Returns a new instance of ExpressionStatementNode.



94
95
96
97
# File 'lib/miniruby/ast.rb', line 94

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

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



91
92
93
# File 'lib/miniruby/ast.rb', line 91

def expression
  @expression
end

Instance Method Details

#==(other) ⇒ Object



100
101
102
103
104
# File 'lib/miniruby/ast.rb', line 100

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

  @expression == other.expression
end

#inspect(indent = 0) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/miniruby/ast.rb', line 112

def inspect(indent = 0)
  buff = String.new
  buff << "#{INDENT_UNIT * indent}(expr_stmt"
  buff << "\n" << @expression.inspect(indent + 1)
  buff << ')'
  buff
end

#to_s(indent = 0) ⇒ Object



107
108
109
# File 'lib/miniruby/ast.rb', line 107

def to_s(indent = 0)
  "#{INDENT_UNIT * indent}#{@expression}\n"
end