Class: Squeel::Nodes::Nary

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

Direct Known Subclasses

And

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PredicateOperators

#-@, #|

Constructor Details

#initialize(children) ⇒ Nary

Returns a new instance of Nary.

Raises:

  • (ArgumentError)


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

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
  # Operators#& method on other nodes. If you're creating And nodes
  # manually, by sure that they're new arays.
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



6
7
8
# File 'lib/squeel/nodes/nary.rb', line 6

def children
  @children
end

Instance Method Details

#&(other) ⇒ Object



16
17
18
19
# File 'lib/squeel/nodes/nary.rb', line 16

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

#-(other) ⇒ Object



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

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

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/squeel/nodes/nary.rb', line 26

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