Class: SyntaxTree::CallOperatorFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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.



2932
2933
2934
# File 'lib/syntax_tree.rb', line 2932

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2930
2931
2932
# File 'lib/syntax_tree.rb', line 2930

def operator
  @operator
end

Instance Method Details

#commentsObject



2936
2937
2938
# File 'lib/syntax_tree.rb', line 2936

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

#format(q) ⇒ Object



2940
2941
2942
2943
2944
2945
2946
# File 'lib/syntax_tree.rb', line 2940

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