Class: SyntaxTree::Unary

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

Overview

Unary represents a unary method being called on an expression, as in ! or ~.

!value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator:, statement:, location:, comments: []) ⇒ Unary

Returns a new instance of Unary.



11563
11564
11565
11566
11567
11568
# File 'lib/syntax_tree.rb', line 11563

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11561
11562
11563
# File 'lib/syntax_tree.rb', line 11561

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11558
11559
11560
# File 'lib/syntax_tree.rb', line 11558

def location
  @location
end

#operatorObject (readonly)

String

the operator being used



11552
11553
11554
# File 'lib/syntax_tree.rb', line 11552

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



11555
11556
11557
# File 'lib/syntax_tree.rb', line 11555

def statement
  @statement
end

Instance Method Details

#child_nodesObject



11570
11571
11572
# File 'lib/syntax_tree.rb', line 11570

def child_nodes
  [statement]
end

#format(q) ⇒ Object



11574
11575
11576
11577
# File 'lib/syntax_tree.rb', line 11574

def format(q)
  q.text(operator)
  q.format(statement)
end

#pretty_print(q) ⇒ Object



11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
# File 'lib/syntax_tree.rb', line 11579

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

    q.breakable
    q.pp(operator)

    q.breakable
    q.pp(statement)

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

#to_json(*opts) ⇒ Object



11593
11594
11595
11596
11597
11598
11599
11600
11601
# File 'lib/syntax_tree.rb', line 11593

def to_json(*opts)
  {
    type: :unary,
    op: operator,
    value: statement,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end