From: Robert Evans Date: 2005-11-15T14:16:54+09:00 Subject: Re: removing a constant definition from an environment Hey Everybody, Thanks for your help. I went for Mark's approach of using Object.instance_eval(:remove_const, :FOO). I want to make sure I understand what is going on, so let me know if I get the reason this works wrong. This works because: Object includes Kernel which is a Module, so it gets all the methods on Module, which includes remove_const. Is that correct? Thanks, Bob Evans On Nov 14, 2005, at 5:44 PM, Mark Hubbart wrote: > On 11/14/05, Mauricio Fern�ndez wrote: >> On Tue, Nov 15, 2005 at 07:16:06AM +0900, Mauricio Fern�ndez wrote: >>> On Tue, Nov 15, 2005 at 06:56:59AM +0900, Robert Evans wrote: >>>> Hi Ryan, >>>> >>>> Thanks for your help. >>>> >>>> I tried that, and it didn't work. Here is my irb transcript trying >>>> that. Is there another way to remove a constant? I thought I had >>>> seen >>>> one in the Pickaxe book, but maybe I was thinking of the module >>>> method. >>>> >>>> irb >>>> irb(main):001:0> FOO = "my symbol value" >>>> => "my symbol value" >>>> irb(main):002:0> remove_const(FOO) >>>> NoMethodError: undefined method `remove_const' for main:Object >>>> from (irb):2 >>>> irb(main):003:0> remove_const(:FOO) >> >> Sorry, I meant >> Object.send(:remove_const, :FOO) > > I may be wrong, but I think using #send to bypass private method > encapsulation is not future-proof. Instead, you might use > > Object.instance_eval{ remove_const :FOO } > > This is almost guaranteed to work in the future. > > cheers, > Mark