[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Destroy object from memory.. Object.const_destroy?

Yukihiro Matsumoto

7/5/2007 2:32:00 PM

Hi,

In message "Re: Destroy object from memory.. Object.const_destroy?"
on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith <beingthexemplary@gmail.com> writes:

|If I'm instantiating a instance of a class at using Object.const_get.
|How can I destroy it so that next time it reloads and code changes will
|take effect?

I am not sure what you mean here. You don't instantiate anything
using const_get. You just get the reference to the existing object.
If you want to redefine class objects (without warning), you remove
the constant using remove_const(), and reload the program using
load(). But I'd recommend restarting the program, unless reloading is
absolutely necessary.

matz.

3 Answers

warhero

7/5/2007 2:40:00 PM

0

Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Destroy object from memory.. Object.const_destroy?"
> on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith
> <beingthexemplary@gmail.com> writes:
>
> |If I'm instantiating a instance of a class at using Object.const_get.
> |How can I destroy it so that next time it reloads and code changes will
> |take effect?
>
> I am not sure what you mean here. You don't instantiate anything
> using const_get. You just get the reference to the existing object.
> If you want to redefine class objects (without warning), you remove
> the constant using remove_const(), and reload the program using
> load(). But I'd recommend restarting the program, unless reloading is
> absolutely necessary.
>
> matz.

Thanks,

That's pretty much what I was looking for. The problem I'm having is
with a plugin in Rails. Once it runs, if code is executed, then changed
at all, I have to restart Rails. Default rails controllers update just
fine. They're probably using the remove_const(). But with my plugin I
want to have the same functionality...

Are there any major risks doing this? Wouldn't seem like it.
Thanks


--
Posted via http://www.ruby-....

James Gray

7/5/2007 2:51:00 PM

0

On Jul 5, 2007, at 9:40 AM, Aaron Smith wrote:

> Yukihiro Matsumoto wrote:
>> Hi,
>>
>> In message "Re: Destroy object from memory.. Object.const_destroy?"
>> on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith
>> <beingthexemplary@gmail.com> writes:
>>
>> |If I'm instantiating a instance of a class at using
>> Object.const_get.
>> |How can I destroy it so that next time it reloads and code
>> changes will
>> |take effect?
>>
>> I am not sure what you mean here. You don't instantiate anything
>> using const_get. You just get the reference to the existing object.
>> If you want to redefine class objects (without warning), you remove
>> the constant using remove_const(), and reload the program using
>> load(). But I'd recommend restarting the program, unless
>> reloading is
>> absolutely necessary.
>>
>> matz.
>
> Thanks,
>
> That's pretty much what I was looking for. The problem I'm having is
> with a plugin in Rails. Once it runs, if code is executed, then
> changed
> at all, I have to restart Rails. Default rails controllers update just
> fine. They're probably using the remove_const(). But with my plugin I
> want to have the same functionality...

Are you talking about the way Rails reloads classes in development
mode? You can enable this in your own classes using:

class MyClass
include Reloadable
end

James Edward Gray II

warhero

7/5/2007 3:03:00 PM

0


>> That's pretty much what I was looking for. The problem I'm having is
>> with a plugin in Rails. Once it runs, if code is executed, then
>> changed
>> at all, I have to restart Rails. Default rails controllers update just
>> fine. They're probably using the remove_const(). But with my plugin I
>> want to have the same functionality...
>
> Are you talking about the way Rails reloads classes in development
> mode? You can enable this in your own classes using:
>
> class MyClass
> include Reloadable
> end
>
> James Edward Gray II

That's another good solution. Thanks.

--
Posted via http://www.ruby-....