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.



4948
4949
4950
4951
# File 'lib/syntax_tree/node.rb', line 4948

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



4943
4944
4945
# File 'lib/syntax_tree/node.rb', line 4943

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



4946
4947
4948
# File 'lib/syntax_tree/node.rb', line 4946

def value
  @value
end

Instance Method Details

#commentsObject



4953
4954
4955
# File 'lib/syntax_tree/node.rb', line 4953

def comments
  []
end

#format(q) ⇒ Object



4957
4958
4959
4960
4961
4962
4963
4964
# File 'lib/syntax_tree/node.rb', line 4957

def format(q)
  q.format(key)

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