[lnkForumImage]
TotalShareware - Download Free Software

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


 

Glenn Parker

3/29/2005 4:41:00 AM

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.tetrafoi...


2 Answers

Simon Strandgaard

3/29/2005 6:17:00 AM

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.

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>


--
Simon Strandgaard


Adelle Hartley

3/29/2005 8:49:00 AM

0

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.