Class: Squeel::Nodes::Nary
- Includes:
- PredicateOperators
- Defined in:
- lib/squeel/nodes/nary.rb
Overview
A node containing multiple children. Just the And node for now.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Array
readonly
This node’s children.
Instance Method Summary collapse
-
#&(other) ⇒ Nary
Returns a new Nary node, with an additional child.
-
#-(other) ⇒ Nary
Returns a new Nary node, with an additional (negated) child.
-
#eql?(other) ⇒ Boolean
Object comparison.
-
#hash ⇒ Object
Implemented for equality testing.
-
#initialize(children) ⇒ Nary
constructor
Creates a new Nary node with the given array of children.
Methods included from PredicateOperators
Constructor Details
#initialize(children) ⇒ Nary
Creates a new Nary node with the given array of children
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
#children ⇒ Array (readonly)
Returns This node’s children.
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 |
#hash ⇒ Object
Implemented for equality testing
35 36 37 |
# File 'lib/squeel/nodes/nary.rb', line 35 def hash @children.hash end |