Class: MiniRuby::AST::IdentifierNode

Inherits:
ExpressionNode show all
Defined in:
lib/miniruby/ast.rb

Overview

Represents an identifier like ‘a`, `foo`

Instance Attribute Summary collapse

Attributes inherited from Node

#span

Instance Method Summary collapse

Constructor Details

#initialize(value:, span: Span::ZERO) ⇒ IdentifierNode

Returns a new instance of IdentifierNode.



301
302
303
304
# File 'lib/miniruby/ast.rb', line 301

def initialize(value:, span: Span::ZERO)
  @span = span
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



298
299
300
# File 'lib/miniruby/ast.rb', line 298

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



307
308
309
310
311
# File 'lib/miniruby/ast.rb', line 307

def ==(other)
  return false unless other.is_a?(IdentifierNode)

  @value == other.value
end

#inspect(indent = 0) ⇒ Object



319
320
321
# File 'lib/miniruby/ast.rb', line 319

def inspect(indent = 0)
  "#{INDENT_UNIT * indent}#{@value}"
end

#to_s(indent = 0) ⇒ Object



314
315
316
# File 'lib/miniruby/ast.rb', line 314

def to_s(indent = 0)
  "#{INDENT_UNIT * indent}#{@value}"
end