Class: MiniRuby::AST::ReturnExpressionNode
- Inherits:
-
ExpressionNode
- Object
- Node
- ExpressionNode
- MiniRuby::AST::ReturnExpressionNode
- Defined in:
- lib/miniruby/ast.rb
Overview
Represents a return like ‘return 3`, `return 1 + 5 * a`
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
: ExpressionNode?.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object other) -> bool.
-
#initialize(value: nil, span: Span::ZERO) ⇒ ReturnExpressionNode
constructor
: (?value: ExpressionNode?, ?span: Span) -> void.
-
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String.
-
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String.
Constructor Details
#initialize(value: nil, span: Span::ZERO) ⇒ ReturnExpressionNode
: (?value: ExpressionNode?, ?span: Span) -> void
426 427 428 429 |
# File 'lib/miniruby/ast.rb', line 426 def initialize(value: nil, span: Span::ZERO) @span = span @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
: ExpressionNode?
423 424 425 |
# File 'lib/miniruby/ast.rb', line 423 def value @value end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
432 433 434 435 436 |
# File 'lib/miniruby/ast.rb', line 432 def ==(other) return false unless other.is_a?(ReturnExpressionNode) @value == other.value end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
450 451 452 453 454 455 456 457 |
# File 'lib/miniruby/ast.rb', line 450 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(return" buff << " #{@value.inspect}" if @value buff << ')' buff end |
#to_s(indent = 0) ⇒ Object
: (?Integer indent) -> String
440 441 442 443 444 445 446 |
# File 'lib/miniruby/ast.rb', line 440 def to_s(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}return" buff << " #{@value}" if @value buff end |