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.



4984
4985
4986
4987
# File 'lib/syntax_tree/node.rb', line 4984

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



4979
4980
4981
# File 'lib/syntax_tree/node.rb', line 4979

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



4982
4983
4984
# File 'lib/syntax_tree/node.rb', line 4982

def value
  @value
end

Instance Method Details

#commentsObject



4989
4990
4991
# File 'lib/syntax_tree/node.rb', line 4989

def comments
  []
end

#format(q) ⇒ Object



4993
4994
4995
4996
4997
4998
4999
5000
# File 'lib/syntax_tree/node.rb', line 4993

def format(q)
  q.format(key)

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