Class: Squeel::Nodes::Nary

Inherits:
Node
  • Object
show all
Includes:
PredicateOperators
Defined in:
lib/squeel/nodes/nary.rb

Overview

A node containing multiple children. Just the And node for now.

Direct Known Subclasses

And

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PredicateOperators

#[email protected], #|

Methods inherited from Node

#each, #grep

Constructor Details

#initialize(children) ⇒ Nary

Creates a new Nary node with the given array of children

Raises:

  • (ArgumentError)

12
13
14
15
16
17
18
# File 'lib/squeel/nodes/nary.rb', line 12

def initialize(children)
  raise ArgumentError, '#{self.class} requires an array' unless Array === children
  # We don't dup here, as incoming arrays should be created by the
  # PredicateOperators#& method on other nodes. If you're creating And nodes
  # manually, by sure that they're new arays.
  @children = children
end

Instance Attribute Details

#childrenArray (readonly)


8
9
10
# File 'lib/squeel/nodes/nary.rb', line 8

def children
  @children
end

Instance Method Details

#&(other) ⇒ Nary

Returns a new Nary node, with an additional child.


23
24
25
# File 'lib/squeel/nodes/nary.rb', line 23

def &(other)
  self.class.new(@children + [other])
end

#-(other) ⇒ Nary

Returns a new Nary node, with an additional (negated) child.


30
31
32
# File 'lib/squeel/nodes/nary.rb', line 30

def -(other)
  self.class.new(@children + [Not.new(other)])
end

#eql?(other) ⇒ Boolean

Object comparison


40
41
42
43
# File 'lib/squeel/nodes/nary.rb', line 40

def eql?(other)
  self.class.eql?(other.class) &&
  self.children.eql?(other.children)
end

#hashObject

Implemented for equality testing


35
36
37
# File 'lib/squeel/nodes/nary.rb', line 35

def hash
  @children.hash
end