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.



4904
4905
4906
4907
# File 'lib/syntax_tree/node.rb', line 4904

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

Instance Attribute Details

#keyObject (readonly)

Label

the keyword being used



4899
4900
4901
# File 'lib/syntax_tree/node.rb', line 4899

def key
  @key
end

#valueObject (readonly)

untyped

the optional value for the keyword



4902
4903
4904
# File 'lib/syntax_tree/node.rb', line 4902

def value
  @value
end

Instance Method Details

#commentsObject



4909
4910
4911
# File 'lib/syntax_tree/node.rb', line 4909

def comments
  []
end

#format(q) ⇒ Object



4913
4914
4915
4916
4917
4918
4919
4920
# File 'lib/syntax_tree/node.rb', line 4913

def format(q)
  q.format(key)

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