------art_40099_22527101.1162667969491
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 11/4/06, Devin Mullins <twifkak / comcast.net> wrote:
>
> $ ri remove_const
> ---------------------------------------------------- Module#remove_const
>       remove_const(sym)   obj
> ------------------------------------------------------------------------
>       Removes the definition of the given constant, returning that
>       constant's value. Predefined classes and singleton objects (such as
>       _true_) cannot be removed.
>
> For a more thorough answer, read the Rails reloading code.
>
> Devin
>
>
How could I have missed that one!!!
Thx.
Well it is not perfect but I think it gets the job done
<begin code>
#!/usr/local/bin/ruby

def redefine_class name, baseject, &definition
       Object.send :remove_const, name.to_s rescue nil
       cls  bject.const_set name.to_s, Class.new( base )
       cls.class_eval &definition if definition
end

class A
end
puts A.object_id
redefine_class A
puts A.object_id
redefine_class A do
    def greet; puts "hi" end
end
A.new.greet
<end code>

Useless code, I love it ;)
Robert
-- 
The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.

- George Bernard Shaw

------art_40099_22527101.1162667969491--