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



2405
2406
2407
# File 'lib/syntax_tree/node.rb', line 2405

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2403
2404
2405
# File 'lib/syntax_tree/node.rb', line 2403

def operator
  @operator
end

Instance Method Details

#commentsObject



2409
2410
2411
# File 'lib/syntax_tree/node.rb', line 2409

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

#format(q) ⇒ Object



2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
# File 'lib/syntax_tree/node.rb', line 2413

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