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.



7375
7376
7377
7378
7379
# File 'lib/syntax_tree.rb', line 7375

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



7373
7374
7375
# File 'lib/syntax_tree.rb', line 7373

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7370
7371
7372
# File 'lib/syntax_tree.rb', line 7370

def location
  @location
end

#valueObject (readonly)

String

the value of the imaginary number literal



7367
7368
7369
# File 'lib/syntax_tree.rb', line 7367

def value
  @value
end

Instance Method Details

#child_nodesObject



7381
7382
7383
# File 'lib/syntax_tree.rb', line 7381

def child_nodes
  []
end

#format(q) ⇒ Object



7385
7386
7387
# File 'lib/syntax_tree.rb', line 7385

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

#pretty_print(q) ⇒ Object



7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
# File 'lib/syntax_tree.rb', line 7389

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



7400
7401
7402
7403
7404
# File 'lib/syntax_tree.rb', line 7400

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