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.



4986
4987
4988
4989
# File 'lib/syntax_tree/node.rb', line 4986

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



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

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



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

def value
  @value
end

Instance Method Details

#commentsObject



4991
4992
4993
# File 'lib/syntax_tree/node.rb', line 4991

def comments
  []
end

#format(q) ⇒ Object



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

def format(q)
  q.format(key)

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