class Unparser::Emitter::HashPattern

Emitter for hash patterns

Public Instance Methods

emit_const_pattern() click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 10
def emit_const_pattern
  parentheses do
    emit_hash_body
  end
end

Private Instance Methods

dispatch() click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 18
def dispatch
  parentheses('{', '}') do
    emit_hash_body
  end
end
emit_hash_body() click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 24
def emit_hash_body
  delimited(children, &method(:emit_member))
end
emit_match_var(node) click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 41
def emit_match_var(node)
  write_symbol_body(node.children.first)
  write(':')
end
emit_member(node) click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 28
def emit_member(node)
  case node.type
  when :pair
    emit_pair(node)
  when :match_var
    emit_match_var(node)
  when :match_rest
    writer_with(MatchRest, node).emit_hash_pattern
  else
    visit(node)
  end
end
emit_pair(node) click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 46
def emit_pair(node)
  key, value = node.children

  if n_sym?(key)
    write_symbol_body(key.children.first)
  else
    visit(s(:dstr, *key))
  end

  write(':')

  ws

  visit(value)
end
write_symbol_body(symbol) click to toggle source
# File lib/unparser/emitter/hash_pattern.rb, line 62
def write_symbol_body(symbol)
  write(symbol.inspect[1..-1])
end