Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abyx/1014031 to your computer and use it in GitHub Desktop.
Save abyx/1014031 to your computer and use it in GitHub Desktop.
Fix SortedSet to ensure objects comparable with <=>
From 9c168445300c6fda62173d37fbbbffa1a2136e03 Mon Sep 17 00:00:00 2001
From: Aviv Ben-Yosef <aviv.by@gmail.com>
Date: Wed, 8 Jun 2011 11:10:11 +0300
Subject: [PATCH] Fix SortedSet to ensure objects comparable with <=>
Fixes 2 failing specs for SortedSet:
- SortedSet#add takes only values which responds <=>
- SortedSet#initialize takes only values which respond to <=>
---
lib/set.rb | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/set.rb b/lib/set.rb
index d110742..8f23443 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -460,6 +460,7 @@ class SortedSet < Set
end
def add(o)
+ raise ArgumentError, "value must respond to <=>" unless o.respond_to?(:<=>)
@keys = nil
@hash[o] = true
self
--
1.7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment