Skip to content
Browse files

Fix issue with 1.8.

Method :<=> does not exist on nil values, and using :<=> on arrays will
call :<=> recursively on its children.
  • Loading branch information...
1 parent 4039081 commit 43ace9a3133af4ba75d6b7c858fc158fa1a4a4df @kouno committed Aug 12, 2012
Showing with 20 additions and 7 deletions.
  1. +18 −5 lib/activefacts/api/instance_index_key.rb
  2. +2 −2 spec/constellation/constellation_spec.rb
View
23 lib/activefacts/api/instance_index_key.rb
@@ -6,11 +6,24 @@ def initialize(hash)
end
def <=>(other)
- result = @value <=> other.value
- if result.nil?
- @value.to_s <=> other.value.to_s
+ if contains_nil?(@value) || contains_nil?(other.value)
+ @value.inspect <=> other.value.inspect
else
- result
+ @value <=> other.value
+ end
+ end
+
+ def contains_nil?(arr)
+ if arr.class.ancestors.include?(Array)
+ arr.any? do |el|
+ if el.nil?
+ true
+ else
+ contains_nil?(el)
+ end
+ end
+ else
+ arr.nil?
end
end
@@ -40,4 +53,4 @@ def flatten_key(key)
key
end
end
-end
+end
View
4 spec/constellation/constellation_spec.rb
@@ -228,13 +228,13 @@ class Mod::Bar; end
it "should support each" do
baz = @constellation.Name("baz")
count = 0
- @constellation.Name.each { |rv| count += 1 }
+ @constellation.Name.each { |_, _| count += 1 }
count.should == 1
end
it "should support detect" do
baz = @constellation.Name("baz")
- @constellation.Name.detect { |rv| true }.should be_true
+ @constellation.Name.detect { |_, _| true }.should be_true
end
end

0 comments on commit 43ace9a

Please sign in to comment.
Something went wrong with that request. Please try again.