From: Mark Hubbart Date: 2005-07-20T23:50:52+09:00 Subject: Re: IRB reset? On 7/20/05, Chuck Brotman wrote: > > "rcoder" wrote in message > news:1121809476.588549.318170@g47g2000cwa.googlegroups.com... > > This isn't specific to IRb -- any time you reload code which defines > > constants, (variables with names that begin with a capital letter, such > > as 'MY_VARIABLE' or 'MyConstant') the Ruby runtime will throw a warning > > about the constant being redefined. > > > > You can see this behavior in its simplest form with code like the > > following: > > > > --- begin 'const_warn_demo.rb' --- > > > > # set a constant > > FOO = 'bar' > > > > # do something... > > > > # now, set the constant again > > FOO = 'baz' > > > > --- end --- > > > > Constants are designed to be read-only values, so a warning when > > they're re-assigned is appropriate. > > > > -Lennon > > > > > Lennon. > > Thanks for your reply! > I understand your answer to part one of my question, do you have anything to > say about part two? I.e. can an IRB session be reset to an uninitialized > state? In other words, is there a way to do an "unload?" or the > equivalent??? A related question might be: can one undefine a constant, > (like one can undef a methiod)? Object.class_eval do const_remove :Foo if defined? Foo const_remove :Bar if defined? Bar end All subconstants (ie, Bar::Baz) will be removed too. Putting code like this near the top of your file will make it not complain about redefining constants. It might be good not to leave the code in there for any release versions, though; it's nice to be able to tell if you somehow accidentally load a library more than once. cheers, Mark