Bug: SortedSet gives warning

In both ruby 1.8.2 and 1.9 (2005-02-10) use of SortedSet gives a warning under "-w".

ruby -w -rset -e 'p SortedSet.new(%w{a b c})'
(eval):2: warning: method redefined; discarding old initialize
#<SortedSet: {"a", "b", "c"}>

This is due to excessive cleverness relating to an alternate internal
representation using the 'rbtree' module (not part of the standard
distribution).

It attempts to "require 'rbtree'" and catches the LoadError if that
fails. It then "evals" a very basic implementation which redefines
'initialize' triggering the warning.

Personally I would prefer that either the rbtree be included in the
distribution or this patch of code to be ripped out and replace by
a simple tree implementation.

I'm prepared to do a simple ruby tree implementation if needed...,
just say the word.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Refactorers do it a little better every time.

Hi,

In both ruby 1.8.2 and 1.9 (2005-02-10) use of SortedSet gives a warning
under "-w".

Here's the patch.
              matz.

--- lib/set.rb 15 Dec 2004 06:35:53 -0000 1.24
+++ lib/set.rb 4 Mar 2005 01:16:06 -0000
@@ -440,2 +440,7 @@ class SortedSet < Set

+ module_eval {
+ # a hack to shut up warning
+ alias old_init initialize
+ remove_method :old_init
+ }
       begin

···

In message "Re: Bug: SortedSet gives warning." on Fri, 4 Mar 2005 10:03:24 +0900, John Carter <john.carter@tait.co.nz> writes:

Thanks!

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Refactorers do it a little better every time.

···

On Fri, 4 Mar 2005, Yukihiro Matsumoto wrote:

Here's the patch.