Module: Unparser::NodeHelpers

Included in:
Emitter, NodeDetails, Writer
Defined in:
lib/unparser/node_helpers.rb

Instance Method Summary collapse

Instance Method Details

#n(type, children = []) ⇒ Parser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Helper for building nodes

Parameters:

  • type (Symbol)
  • children (Array) (defaults to: [])

Returns:

  • (Parser::AST::Node)


26
27
28
# File 'lib/unparser/node_helpers.rb', line 26

def n(type, children = [])
  Parser::AST::Node.new(type, children)
end

#n?(type, node) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/unparser/node_helpers.rb', line 30

def n?(type, node)
  node.type.equal?(type)
end

#s(type, *children) ⇒ Parser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Helper for building nodes

Parameters:

  • type (Symbol)
  • children (Parser::AST::Node)

Returns:

  • (Parser::AST::Node)


14
15
16
# File 'lib/unparser/node_helpers.rb', line 14

def s(type, *children)
  Parser::AST::Node.new(type, children)
end

#unwrap_single_begin(node) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/unparser/node_helpers.rb', line 72

def unwrap_single_begin(node)
  if n_begin?(node) && node.children.one?
    node.children.first
  else
    node
  end
end