Class: SyntaxTree::Imaginary

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Imaginary represents an imaginary number literal.

1i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Imaginary

Returns a new instance of Imaginary.



7243
7244
7245
7246
7247
# File 'lib/syntax_tree.rb', line 7243

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7241
7242
7243
# File 'lib/syntax_tree.rb', line 7241

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7238
7239
7240
# File 'lib/syntax_tree.rb', line 7238

def location
  @location
end

#valueObject (readonly)

String

the value of the imaginary number literal



7235
7236
7237
# File 'lib/syntax_tree.rb', line 7235

def value
  @value
end

Instance Method Details

#child_nodesObject



7249
7250
7251
# File 'lib/syntax_tree.rb', line 7249

def child_nodes
  []
end

#format(q) ⇒ Object



7253
7254
7255
# File 'lib/syntax_tree.rb', line 7253

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
# File 'lib/syntax_tree.rb', line 7257

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("imaginary")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



7268
7269
7270
7271
7272
# File 'lib/syntax_tree.rb', line 7268

def to_json(*opts)
  { type: :imaginary, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end