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.



2319
2320
2321
# File 'lib/syntax_tree/node.rb', line 2319

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

:“::” | Op | Period

the operator being formatted



2317
2318
2319
# File 'lib/syntax_tree/node.rb', line 2317

def operator
  @operator
end

Instance Method Details

#commentsObject



2323
2324
2325
# File 'lib/syntax_tree/node.rb', line 2323

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

#format(q) ⇒ Object



2327
2328
2329
2330
2331
2332
2333
2334
# File 'lib/syntax_tree/node.rb', line 2327

def format(q)
  case operator
  in :"::" | Op[value: "::"]
    q.text(".")
  else
    operator.format(q)
  end
end