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.



5895
5896
5897
5898
# File 'lib/syntax_tree/node.rb', line 5895

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



5890
5891
5892
# File 'lib/syntax_tree/node.rb', line 5890

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



5893
5894
5895
# File 'lib/syntax_tree/node.rb', line 5893

def value
  @value
end

Instance Method Details

#commentsObject



5900
5901
5902
# File 'lib/syntax_tree/node.rb', line 5900

def comments
  []
end

#format(q) ⇒ Object



5904
5905
5906
5907
5908
5909
5910
5911
# File 'lib/syntax_tree/node.rb', line 5904

def format(q)
  q.format(key)

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