Class: ActiveFacts::API::KeyArray
- Defined in:
- lib/activefacts/api/instance_index.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Object
This is used by RBTree for searching, and we need it to use eql? semantics to be like a Hash.
-
#initialize(a) ⇒ KeyArray
constructor
A new instance of KeyArray.
- #inspect ⇒ Object
Constructor Details
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/activefacts/api/instance_index.rb', line 35 def <=>(other) unless other.is_a?(Array) # Any kind of Array, not just KeyArray return 1 end 0.upto(size-1) do |i| diff = ((s = self[i]) <=> (o = other[i]) rescue nil) case diff when 0 # Same value, whether exactly the same class or not next when nil # Non-comparable values return -1 if s == nil # Ensure that nil values come before other values return 1 if o == nil diff = s.class.name <=> o.class.name # Otherwise just ensure stable sorting return diff if diff != 0 else return diff end end 0 end |
#==(other) ⇒ Object
This is used by RBTree for searching, and we need it to use eql? semantics to be like a Hash
31 32 33 |
# File 'lib/activefacts/api/instance_index.rb', line 31 def ==(other) self.eql? other end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/activefacts/api/instance_index.rb', line 26 def inspect "KeyArray"+super end |