Class: Unparser::AST::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat, Enumerable
Defined in:
lib/unparser/ast.rb

Overview

AST enumerator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(node, controller = TAUTOLOGY) ⇒ Enumerator

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.

Return new instance

Parameters:

  • node (Parser::AST::Node)
  • controller (#call(node)) (defaults to: TAUTOLOGY)

Returns:



87
88
89
# File 'lib/unparser/ast.rb', line 87

def self.new(node, controller = TAUTOLOGY)
  super
end

Instance Method Details

#each(&block) ⇒ Enumerator<Parser::AST::Node>, self

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.

Return each node

Returns:

  • (Enumerator<Parser::AST::Node>)

    if no block given

  • (self)

    otherwise



101
102
103
104
# File 'lib/unparser/ast.rb', line 101

def each(&block)
  return to_enum unless block_given?
  Walker.call(node, controller, &block)
end

#type(type) ⇒ Enumerable<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.

Return nodes selected by type

Parameters:

  • type (Symbol)

Returns:

  • (Enumerable<Parser::AST::Node>)


126
127
128
# File 'lib/unparser/ast.rb', line 126

def type(type)
  select { |node| node.type.equal?(type) }
end

#types(types) ⇒ Enumerable<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.

Return nodes selected by types

Parameters:

  • types (Enumerable<Symbol>)

Returns:

  • (Enumerable<Parser::AST::Node>)


114
115
116
# File 'lib/unparser/ast.rb', line 114

def types(types)
  select { |node| types.include?(node.type) }
end