Class: MiniRuby::AST::ModifierExpressionNode
- Inherits:
-
ExpressionNode
- Object
- Node
- ExpressionNode
- MiniRuby::AST::ModifierExpressionNode
- Defined in:
- lib/miniruby/ast.rb
Overview
Represents a modifier expression like ‘return 5 if foo`
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) ⇒ ModifierExpressionNode
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) ⇒ ModifierExpressionNode
: (operator: Token, left: ExpressionNode, right: ExpressionNode, ?span: Span) -> void
223 224 225 226 227 228 |
# File 'lib/miniruby/ast.rb', line 223 def initialize(operator:, left:, right:, span: Span::ZERO) @span = span @operator = operator @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
: ExpressionNode
217 218 219 |
# File 'lib/miniruby/ast.rb', line 217 def left @left end |
#operator ⇒ Object (readonly)
: Token
214 215 216 |
# File 'lib/miniruby/ast.rb', line 214 def operator @operator end |
#right ⇒ Object (readonly)
: ExpressionNode
220 221 222 |
# File 'lib/miniruby/ast.rb', line 220 def right @right end |
Instance Method Details
#==(other) ⇒ Object
: (Object other) -> bool
231 232 233 234 235 236 237 |
# File 'lib/miniruby/ast.rb', line 231 def ==(other) return false unless other.is_a?(ModifierExpressionNode) @operator == other.operator && @left == other.left && @right == other.right end |
#inspect(indent = 0) ⇒ Object
: (?Integer indent) -> String
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/miniruby/ast.rb', line 247 def inspect(indent = 0) buff = String.new buff << "#{INDENT_UNIT * indent}(modifier" 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
241 242 243 |
# File 'lib/miniruby/ast.rb', line 241 def to_s(indent = 0) "#{INDENT_UNIT * indent}#{@left} #{@operator} #{@right}" end |