Method: Parser::AST::Node#strip_curly_braces

Defined in:
lib/synvert/core/node_ext.rb

#strip_curly_bracesString

Strip curly braces for hash.

Examples:

node # s(:hash, s(:pair, s(:sym, :foo), s(:str, "bar")))
node.strip_curly_braces # "foo: 'bar'"

Returns:

  • (String)


549
550
551
552
553
# File 'lib/synvert/core/node_ext.rb', line 549

def strip_curly_braces
  return to_source unless type == :hash

  to_source.sub(/^{(.*)}$/) { Regexp.last_match(1).strip }
end