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.



2702
2703
2704
# File 'lib/syntax_tree/node.rb', line 2702

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2700
2701
2702
# File 'lib/syntax_tree/node.rb', line 2700

def operator
  @operator
end

Instance Method Details

#commentsObject



2706
2707
2708
# File 'lib/syntax_tree/node.rb', line 2706

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

#format(q) ⇒ Object



2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
# File 'lib/syntax_tree/node.rb', line 2710

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