diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-07 17:32:48 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-07 17:32:48 +0000 |
| commit | aa8e1885265ac1052cbf12aa9a5c045c3c805e8d (patch) | |
| tree | 984f32a4272a8f871d2289f7d373971a86bea81c /lib | |
| parent | 3748c9c787619f76a62d8c4a2a34f2ad1852e75d (diff) | |
| download | ruby-aa8e1885265ac1052cbf12aa9a5c045c3c805e8d.tar.gz ruby-aa8e1885265ac1052cbf12aa9a5c045c3c805e8d.tar.xz ruby-aa8e1885265ac1052cbf12aa9a5c045c3c805e8d.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@23363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/set.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/set.rb b/lib/set.rb index 6d298d3f8..8f2bef91b 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 <em>mutually comparable</em>: <tt>el1 <=> # el2</tt> must not return <tt>nil</tt> for any elements <tt>el1</tt> @@ -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 |
