Class: MiniRuby::AST::StringLiteralNode

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

Overview

Represents a string literal eg. ‘“foo”`

Instance Attribute Summary collapse

Attributes inherited from Node

#span

Instance Method Summary collapse

Constructor Details

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

: (value: String, ?span: Span) -> void



918
919
920
921
# File 'lib/miniruby/ast.rb', line 918

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

Instance Attribute Details

#valueObject (readonly)

: String



915
916
917
# File 'lib/miniruby/ast.rb', line 915

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object

: (Object other) -> bool



924
925
926
927
928
# File 'lib/miniruby/ast.rb', line 924

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

  @value == other.value
end

#inspect(indent = 0) ⇒ Object

: (?Integer indent) -> String



938
939
940
# File 'lib/miniruby/ast.rb', line 938

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

#to_s(indent = 0) ⇒ Object

: (?Integer indent) -> String



932
933
934
# File 'lib/miniruby/ast.rb', line 932

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