From 77b04fb6d55dc7b0b151e71f7698b612cc6028f3 Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 7 May 2009 17:32:48 +0000 Subject: * lib/set.rb (SortedSet#add): Do not require each newly added element to be Comparable but to respond to <=>. [ruby-dev:38371] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/set.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/set.rb') diff --git a/lib/set.rb b/lib/set.rb index 6d298d3f85..8f2bef91ba 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -456,8 +456,8 @@ end # yielded in sorted order (according to the return values of their # #<=> methods) when iterating over them. # -# All elements that are added to a SortedSet must include the -# Comparable module. +# All elements that are added to a SortedSet must respond to the <=> +# method for comparison. # # Also, all elements must be mutually comparable: el1 <=> # el2 must not return nil for any elements el1 @@ -506,7 +506,7 @@ class SortedSet < Set end def add(o) - o.is_a?(Comparable) or raise ArgumentError, "value must be comparable" + o.respond_to?(:<=>) or raise ArgumentError, "value must repond to <=>" super end alias << add @@ -529,7 +529,7 @@ class SortedSet < Set end def add(o) - o.is_a?(Comparable) or raise ArgumentError, "value must be comparable" + o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>" @keys = nil super end -- cgit v1.2.3