Class: MiniRuby::AST::ProgramNode
Overview
Represents a program
Instance Attribute Summary collapse
-
#statements ⇒ Object
readonly
: Array.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object other) -> bool.
-
#initialize(statements:, span: Span::ZERO) ⇒ ProgramNode
constructor
: (statements: Array, ?span: Span) -> void.
-
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String.
-
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String.
Constructor Details
#initialize(statements:, span: Span::ZERO) ⇒ ProgramNode
: (statements: Array, ?span: Span) -> void
47 48 49 50 |
# File 'lib/miniruby/ast.rb', line 47 def initialize(statements:, span: Span::ZERO) @span = span @statements = statements end |
Instance Attribute Details
#statements ⇒ Object (readonly)
: Array
44 45 46 |
# File 'lib/miniruby/ast.rb', line 44 def statements @statements end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
53 54 55 56 57 |
# File 'lib/miniruby/ast.rb', line 53 def ==(other) return false unless other.is_a?(ProgramNode) @statements == other.statements end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/miniruby/ast.rb', line 73 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(program" @statements.each do |stmt| buff << "\n" << stmt.inspect(indent + 1) end buff << ')' buff end |
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String
61 62 63 64 65 66 67 68 69 |
# File 'lib/miniruby/ast.rb', line 61 def to_s(indent = 0) buffer = String.new @statements.each do |stmt| buffer << stmt.to_s(indent) end buffer end |