Bug: SortedSet gives warning.

J

John Carter

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 : (e-mail address removed)
New Zealand

Refactorers do it a little better every time.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Bug: SortedSet gives warning."

|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 :eek:ld_init
+ }
begin
 
J

John Carter

Here's the patch.

Thanks!

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand

Refactorers do it a little better every time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top