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



6805
6806
6807
6808
6809
# File 'lib/syntax_tree.rb', line 6805

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



6803
6804
6805
# File 'lib/syntax_tree.rb', line 6803

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6800
6801
6802
# File 'lib/syntax_tree.rb', line 6800

def location
  @location
end

#valueObject (readonly)

String

the value of the imaginary number literal



6797
6798
6799
# File 'lib/syntax_tree.rb', line 6797

def value
  @value
end

Instance Method Details

#child_nodesObject



6811
6812
6813
# File 'lib/syntax_tree.rb', line 6811

def child_nodes
  []
end

#format(q) ⇒ Object



6815
6816
6817
# File 'lib/syntax_tree.rb', line 6815

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

#pretty_print(q) ⇒ Object



6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
# File 'lib/syntax_tree.rb', line 6819

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



6830
6831
6832
6833
6834
# File 'lib/syntax_tree.rb', line 6830

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