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.



4939
4940
4941
4942
# File 'lib/syntax_tree/node.rb', line 4939

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

Instance Attribute Details

#key ⇒ Object (readonly)

[Label] the keyword being used



4934
4935
4936
# File 'lib/syntax_tree/node.rb', line 4934

def key
  @key
end

#value ⇒ Object (readonly)

[untyped] the optional value for the keyword



4937
4938
4939
# File 'lib/syntax_tree/node.rb', line 4937

def value
  @value
end

Instance Method Details

#comments ⇒ Object



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

def comments
  []
end

#format(q) ⇒ Object



4948
4949
4950
4951
4952
4953
4954
4955
# File 'lib/syntax_tree/node.rb', line 4948

def format(q)
  q.format(key)

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