Class: SyntaxTree::HshPtn::KeywordFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Formats a key-value pair in a hash pattern. The value is optional.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ KeywordFormatter

Returns a new instance of KeywordFormatter.



5890
5891
5892
5893
# File 'lib/syntax_tree/node.rb', line 5890

def initialize(key, value)
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5885
5886
5887
# File 'lib/syntax_tree/node.rb', line 5885

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



5888
5889
5890
# File 'lib/syntax_tree/node.rb', line 5888

def value
  @value
end

Instance Method Details

#commentsObject



5895
5896
5897
# File 'lib/syntax_tree/node.rb', line 5895

def comments
  []
end

#format(q) ⇒ Object



5899
5900
5901
5902
5903
5904
5905
5906
# File 'lib/syntax_tree/node.rb', line 5899

def format(q)
  q.format(key)

  if value
    q.text(" ")
    q.format(value)
  end
end