Class: Squeel::Nodes::Nary

Inherits:
Object
  • 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

#-@, #|

Constructor Details

#initialize(children) ⇒ Nary

Creates a new Nary node with the given array of children

Parameters:

  • children (Array)

    The node’s 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)

Returns This node’s children.

Returns:

  • (Array)

    This node’s children



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

def children
  @children
end

Instance Method Details

#&(other) ⇒ Nary

Add a new child to the node’s children

Parameters:

  • other

    A new child node

Returns:

  • (Nary)

    This node, with its updated children.



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

def &(other)
  @children << other
  self
end

#-(other) ⇒ Nary

Append a new Not node to this node’s children

Parameters:

  • other

    A new child node

Returns:

  • (Nary)

    This node, with its new, negated child



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

def -(other)
  @children << Not.new(other)
  self
end

#eql?(other) ⇒ Boolean

Object comparison

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/squeel/nodes/nary.rb', line 42

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

#hashObject

Implemented for equality testing



37
38
39
# File 'lib/squeel/nodes/nary.rb', line 37

def hash
  @children.hash
end