Hi all,
Being able to create constants at run-time using Object.const_set is neat
and all, but is there a way of un-setting them?
Adelle.
Hi all,
Being able to create constants at run-time using Object.const_set is neat
and all, but is there a way of un-setting them?
Adelle.
Adelle Hartley wrote:
Hi all,
Being able to create constants at run-time using Object.const_set is neat
and all, but is there a way of un-setting them?
It is actually Module.const_set, and there is also Module.remove_const, but that method is private. You may need to use send to invoke it.
--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoil.com/>
something like this:
irb(main):003:0> Object.const_set(:C, 42)
=> 42
irb(main):004:0> Object.send(:remove_const,:C) if Object.const_defined?(:C)
=> 42
irb(main):005:0> C
NameError: uninitialized constant C
from (irb):5
irb(main):006:0>
On Tue, 29 Mar 2005 13:40:35 +0900, Glenn Parker <glenn.parker@comcast.net> wrote:
Adelle Hartley wrote:
> Hi all,
>
> Being able to create constants at run-time using Object.const_set is neat
> and all, but is there a way of un-setting them?It is actually Module.const_set, and there is also Module.remove_const,
but that method is private. You may need to use send to invoke it.
--
Simon Strandgaard
Simon Strandgaard wrote:
<glenn.parker@comcast.net> wrote:
> Adelle Hartley wrote:
> > Being able to create constants at run-time using
Object.const_set is
> > neat and all, but is there a way of un-setting them?
>
> It is actually Module.const_set, and there is also
> Module.remove_const, but that method is private. You may
need to use send to invoke it.something like this:
irb(main):003:0> Object.const_set(:C, 42) => 42
irb(main):004:0> Object.send(:remove_const,:C) if
Object.const_defined?(:C) => 42 irb(main):005:0> C
NameError: uninitialized constant C
from (irb):5
irb(main):006:0>
Thankyou both. That's working perfectly!
Adelle.