Class: Squeel::Nodes::Node

Inherits:
Object
  • Object
show all
Includes:
Polyamorous::TreeNode
Defined in:
lib/squeel/nodes/node.rb

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object


8
9
10
11
12
# File 'lib/squeel/nodes/node.rb', line 8

def each(&block)
  return enum_for(:each) unless block_given?

  Visitors::EnumerationVisitor.new(block).accept(self)
end

#grep(object, &block) ⇒ Object

We don't want the full Enumerable method list, because it will mess with stuff like KeyPath


16
17
18
19
20
21
22
23
24
# File 'lib/squeel/nodes/node.rb', line 16

def grep(object, &block)
  if block_given?
    each { |value| yield value if object === value }
  else
    [].tap do |results|
      each { |value| results << value if object === value }
    end
  end
end