Class: MiniRuby::AST::UnaryExpressionNode
- Inherits:
-
ExpressionNode
- Object
- Node
- ExpressionNode
- MiniRuby::AST::UnaryExpressionNode
- Defined in:
- lib/miniruby/ast.rb
Overview
Represents an expression with a unary operator like ‘+3`, `-a`
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
: Token.
-
#value ⇒ Object
readonly
: ExpressionNode.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object other) -> bool.
-
#initialize(operator:, value:, span: Span::ZERO) ⇒ UnaryExpressionNode
constructor
: (operator: Token, value: ExpressionNode, ?span: Span) -> void.
-
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String.
-
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String.
Constructor Details
#initialize(operator:, value:, span: Span::ZERO) ⇒ UnaryExpressionNode
: (operator: Token, value: ExpressionNode, ?span: Span) -> void
386 387 388 389 390 |
# File 'lib/miniruby/ast.rb', line 386 def initialize(operator:, value:, span: Span::ZERO) @span = span @operator = operator @value = value end |
Instance Attribute Details
#operator ⇒ Object (readonly)
: Token
380 381 382 |
# File 'lib/miniruby/ast.rb', line 380 def operator @operator end |
#value ⇒ Object (readonly)
: ExpressionNode
383 384 385 |
# File 'lib/miniruby/ast.rb', line 383 def value @value end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
393 394 395 396 397 398 |
# File 'lib/miniruby/ast.rb', line 393 def ==(other) return false unless other.is_a?(UnaryExpressionNode) @operator == other.operator && @value == other.value end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
408 409 410 411 412 413 414 415 416 417 |
# File 'lib/miniruby/ast.rb', line 408 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(unary_expr" buff << "\n#{INDENT_UNIT * (indent + 1)}#{@operator}" buff << "\n" << @value.inspect(indent + 1) buff << ')' buff end |
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String
402 403 404 |
# File 'lib/miniruby/ast.rb', line 402 def to_s(indent = 0) "#{INDENT_UNIT * indent}#{@operator}#{@value}" end |