[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

warning: refine foo, what!?

_ugly

7/3/2005 4:34:00 PM

I've been doing some unit tests with ruby -W. Wow did I have a lot to
clean up but I still can't get past one warning. I've boiled it down
to this example:

o = Object.new
def o.foo
'foo'
end
class << o
undef_method :foo
end
def o.foo
'foo'
end

# undef_method_test.rb:8: warning: redefine foo

Is my head broken or ruby -W broken? I'm thinking the former.

TIA,
_ugly

4 Answers

Daniel Brockman

7/3/2005 7:06:00 PM

0

_ugly

7/3/2005 7:30:00 PM

0

ah, thank you very much. see, it was the former.

_ugly

Robert Klemme

7/3/2005 9:28:00 PM

0

_ugly <mgarriss@gmail.com> wrote:
> I've been doing some unit tests with ruby -W. Wow did I have a lot to
> clean up but I still can't get past one warning. I've boiled it down
> to this example:
>
> o = Object.new
> def o.foo
> 'foo'
> end
> class << o
> undef_method :foo
> end
> def o.foo
> 'foo'
> end
>
> # undef_method_test.rb:8: warning: redefine foo
>
> Is my head broken or ruby -W broken? I'm thinking the former.

Do you want your head fixed? :-)

Mayby it's the way undef_method works. I never looked at the internals but
maybe the knowledge is kept somewhere that foo was defined at some point in
time.

Kind regards

robert

Nakada, Nobuyoshi

7/4/2005 2:54:00 AM

0

Hi,

At Mon, 4 Jul 2005 01:35:43 +0900,
_ugly wrote in [ruby-talk:147106]:
> Is my head broken or ruby -W broken? I'm thinking the former.

I think it's the latter, because it doesn't appear when
redefining undefined ordinary methods.


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.796
diff -U2 -p -r1.796 eval.c
--- eval.c 2 Jul 2005 08:20:25 -0000 1.796
+++ eval.c 4 Jul 2005 02:32:14 -0000
@@ -3914,5 +3914,5 @@ rb_eval(self, n)
rb_raise(rb_eSecurityError, "redefining method prohibited");
}
- if (RTEST(ruby_verbose)) {
+ if (body && RTEST(ruby_verbose) && body->nd_cnt == 0 && body->nd_body) {
rb_warning("redefine %s", rb_id2name(node->nd_mid));
}


--
Nobu Nakada