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.



2608
2609
2610
# File 'lib/syntax_tree/node.rb', line 2608

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2606
2607
2608
# File 'lib/syntax_tree/node.rb', line 2606

def operator
  @operator
end

Instance Method Details

#commentsObject



2612
2613
2614
# File 'lib/syntax_tree/node.rb', line 2612

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

#format(q) ⇒ Object



2616
2617
2618
2619
2620
2621
2622
# File 'lib/syntax_tree/node.rb', line 2616

def format(q)
  if operator == :"::" || (operator.is_a?(Op) && operator.value == "::")
    q.text(".")
  else
    operator.format(q)
  end
end