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



5147
5148
5149
5150
# File 'lib/syntax_tree/node.rb', line 5147

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5142
5143
5144
# File 'lib/syntax_tree/node.rb', line 5142

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



5145
5146
5147
# File 'lib/syntax_tree/node.rb', line 5145

def value
  @value
end

Instance Method Details

#commentsObject



5152
5153
5154
# File 'lib/syntax_tree/node.rb', line 5152

def comments
  []
end

#format(q) ⇒ Object



5156
5157
5158
5159
5160
5161
5162
5163
# File 'lib/syntax_tree/node.rb', line 5156

def format(q)
  q.format(key)

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