From b77295d7dee6747f560a61f43daf902b62b85462 Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 7 May 2009 17:35:55 +0000 Subject: [PATCH] * 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/branches/ruby_1_8@23365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/set.rb | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ad8d9706d..9841698673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri May 8 02:34:25 2009 Akinori MUSHA + + * lib/set.rb (SortedSet#add): Do not require each newly added + element to be Comparable but to respond to <=>. [ruby-dev:38371] + Thu May 7 13:58:52 2009 Nobuyoshi Nakada * range.c (range_eql): fixed rdoc. diff --git a/lib/set.rb b/lib/set.rb index b352cdd991..3723c8e050 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -446,8 +446,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 @@ -496,7 +496,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 @@ -519,7 +519,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