Class: MiniRuby::AST::BinaryExpressionNode
- Inherits:
-
ExpressionNode
- Object
- Node
- ExpressionNode
- MiniRuby::AST::BinaryExpressionNode
- Defined in:
- lib/miniruby/ast.rb
Overview
Represents an expression with a binary operator like ‘2 + 3`, `a == 4`, `5 < 2`
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
: ExpressionNode.
-
#operator ⇒ Object
readonly
: Token.
-
#right ⇒ Object
readonly
: ExpressionNode.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object other) -> bool.
-
#initialize(operator:, left:, right:, span: Span::ZERO) ⇒ BinaryExpressionNode
constructor
: (operator: Token, left: ExpressionNode, right: ExpressionNode, ?span: Span) -> void.
-
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String.
-
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String.
Constructor Details
#initialize(operator:, left:, right:, span: Span::ZERO) ⇒ BinaryExpressionNode
: (operator: Token, left: ExpressionNode, right: ExpressionNode, ?span: Span) -> void
174 175 176 177 178 179 |
# File 'lib/miniruby/ast.rb', line 174 def initialize(operator:, left:, right:, span: Span::ZERO) @span = span @operator = operator @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
: ExpressionNode
168 169 170 |
# File 'lib/miniruby/ast.rb', line 168 def left @left end |
#operator ⇒ Object (readonly)
: Token
165 166 167 |
# File 'lib/miniruby/ast.rb', line 165 def operator @operator end |
#right ⇒ Object (readonly)
: ExpressionNode
171 172 173 |
# File 'lib/miniruby/ast.rb', line 171 def right @right end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
182 183 184 185 186 187 188 |
# File 'lib/miniruby/ast.rb', line 182 def ==(other) return false unless other.is_a?(BinaryExpressionNode) @operator == other.operator && @left == other.left && @right == other.right end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/miniruby/ast.rb', line 198 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(bin_expr" buff << "\n#{INDENT_UNIT * (indent + 1)}#{@operator}" buff << "\n" << @left.inspect(indent + 1) buff << "\n" << @right.inspect(indent + 1) buff << ')' buff end |
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String
192 193 194 |
# File 'lib/miniruby/ast.rb', line 192 def to_s(indent = 0) "#{INDENT_UNIT * indent}#{@left} #{@operator} #{@right}" end |