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.



4998
4999
5000
5001
# File 'lib/syntax_tree/node.rb', line 4998

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



4993
4994
4995
# File 'lib/syntax_tree/node.rb', line 4993

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



4996
4997
4998
# File 'lib/syntax_tree/node.rb', line 4996

def value
  @value
end

Instance Method Details

#commentsObject



5003
5004
5005
# File 'lib/syntax_tree/node.rb', line 5003

def comments
  []
end

#format(q) ⇒ Object



5007
5008
5009
5010
5011
5012
5013
5014
# File 'lib/syntax_tree/node.rb', line 5007

def format(q)
  q.format(key)

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