Class: SyntaxTree::CallOperatorFormatter

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

Overview

Wraps a call operator (which can be a string literal

or an Op node or a

Period node) and formats it when called.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator) ⇒ CallOperatorFormatter

Returns a new instance of CallOperatorFormatter.



2648
2649
2650
# File 'lib/syntax_tree/node.rb', line 2648

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2646
2647
2648
# File 'lib/syntax_tree/node.rb', line 2646

def operator
  @operator
end

Instance Method Details

#commentsObject



2652
2653
2654
# File 'lib/syntax_tree/node.rb', line 2652

def comments
  operator == :"::" ? [] : operator.comments
end

#format(q) ⇒ Object



2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
# File 'lib/syntax_tree/node.rb', line 2656

def format(q)
  case operator
  when :"::"
    q.text(".")
  when Op
    operator.value == "::" ? q.text(".") : operator.format(q)
  else
    operator.format(q)
  end
end