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.



12067
12068
12069
12070
12071
12072
# File 'lib/syntax_tree.rb', line 12067

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



12065
12066
12067
# File 'lib/syntax_tree.rb', line 12065

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12062
12063
12064
# File 'lib/syntax_tree.rb', line 12062

def location
  @location
end

#operatorObject (readonly)

String

the operator being used



12056
12057
12058
# File 'lib/syntax_tree.rb', line 12056

def operator
  @operator
end

#statementObject (readonly)

untyped

the statement on which to operate



12059
12060
12061
# File 'lib/syntax_tree.rb', line 12059

def statement
  @statement
end

Instance Method Details

#child_nodesObject



12074
12075
12076
# File 'lib/syntax_tree.rb', line 12074

def child_nodes
  [statement]
end

#format(q) ⇒ Object



12078
12079
12080
12081
# File 'lib/syntax_tree.rb', line 12078

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

#pretty_print(q) ⇒ Object



12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
# File 'lib/syntax_tree.rb', line 12083

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



12097
12098
12099
12100
12101
12102
12103
12104
12105
# File 'lib/syntax_tree.rb', line 12097

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