Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Reset the whole state

Reply
Thread Tools

Reset the whole state

 
 
Remi Gillig
Guest
Posts: n/a
 
      06-13-2008
Hello,

I just seached about this problem and found two 2 years old threads :
http://groups.google.com/group/comp....5a099efd08f70d
http://groups.google.com/group/comp....6fa1a935e50697

Each of these talk about how to reset the whole Ruby state, like
starting from a clean interpreter but without rerunning it. More or
less like emptying everything and putting back the predefined
constants, modules and classes.

The first thread has a solution which is using remove_const to not be
able to create classes anymore but this actually does not work
properly because you can still do this :
# class Hello end
# $hello = Hello
# Object.instance_eval("remove_const :Hello")
# h = $hello.new

I'm quite surprised that there was nothing about this in over 2 years
of development. Maybe there are some explanation inside the Ruby
Hacking Guide but most of it is in Japanese.

Anybody has any idea on how to implement this? Thanks.

Remi Gillig.
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      06-13-2008
On 13.06.2008 16:57, Remi Gillig wrote:
> Hello,
>
> I just seached about this problem and found two 2 years old threads :
> http://groups.google.com/group/comp....5a099efd08f70d
> http://groups.google.com/group/comp....6fa1a935e50697
>
> Each of these talk about how to reset the whole Ruby state, like
> starting from a clean interpreter but without rerunning it. More or
> less like emptying everything and putting back the predefined
> constants, modules and classes.
>
> The first thread has a solution which is using remove_const to not be
> able to create classes anymore but this actually does not work
> properly because you can still do this :
> # class Hello end
> # $hello = Hello
> # Object.instance_eval("remove_const :Hello")
> # h = $hello.new
>
> I'm quite surprised that there was nothing about this in over 2 years
> of development. Maybe there are some explanation inside the Ruby
> Hacking Guide but most of it is in Japanese.
>
> Anybody has any idea on how to implement this? Thanks.


I am wondering what you need that for. I guess removal is pretty
complex and thus time consuming because even a freshly started Ruby
interpreter does contain some classes and method definitions. And
creating a process isn't that expensive.

Having said that, maybe you can look at how Ruby can be embedded in C
programs. Then you could create a new initial context if something like
that exists.

Cheers

robert
 
Reply With Quote
 
 
 
 
Remi Gillig
Guest
Posts: n/a
 
      06-14-2008
On Jun 13, 6:09 pm, Robert Klemme <(E-Mail Removed)> wrote:
> On 13.06.2008 16:57, Remi Gillig wrote:
>
>
>
> > Hello,

>
> > I just seached about this problem and found two 2 years old threads :
> >http://groups.google.com/group/comp....read/thread/87...
> >http://groups.google.com/group/comp....read/thread/3e...

>
> > Each of these talk about how to reset the whole Ruby state, like
> > starting from a clean interpreter but without rerunning it. More or
> > less like emptying everything and putting back the predefined
> > constants, modules and classes.

>
> > The first thread has a solution which is using remove_const to not be
> > able to create classes anymore but this actually does not work
> > properly because you can still do this :
> > # class Hello end
> > # $hello = Hello
> > # Object.instance_eval("remove_const :Hello")
> > # h = $hello.new

>
> > I'm quite surprised that there was nothing about this in over 2 years
> > of development. Maybe there are some explanation inside the Ruby
> > Hacking Guide but most of it is in Japanese.

>
> > Anybody has any idea on how to implement this? Thanks.

>
> I am wondering what you need that for. I guess removal is pretty
> complex and thus time consuming because even a freshly started Ruby
> interpreter does contain some classes and method definitions. And
> creating a process isn't that expensive.
>
> Having said that, maybe you can look at how Ruby can be embedded in C
> programs. Then you could create a new initial context if something like
> that exists.
>
> Cheers
>
> robert


It's actually embedding that I'm using right now. I am using Ruby as a
script language for a code editor to perform operations on text etc.
There is a script which is loaded when the program loads which
contains
some classes defined by the user for example. I would like to be able
to
reload this script without having warnings about constants, having
classes mixed together if the user changed the name of a function
between the loadings or still having the same global variables.

Remi Gillig.
 
Reply With Quote
 
David Marchaland
Guest
Posts: n/a
 
      02-09-2010
Hi Remi,

I have the same approach that you describe in your post regarding
embedded Ruby interpreter. I did some trial based on dl library in C to
dynamically open and close Ruby interpreter but I had some issue due to
dlclose() behavior when a so library is loaded into Ruby.

Do you find any solution to restart your Ruby interpreter?

Thanks,
David

Remi Gillig wrote:
> On Jun 13, 6:09 pm, Robert Klemme <(E-Mail Removed)> wrote:
>> > Each of these talk about how to reset the whole Ruby state, like
>> > # h = $hello.new

>> creating a process isn't that expensive.
>>
>> Having said that, maybe you can look at how Ruby can be embedded in C
>> programs. Then you could create a new initial context if something like
>> that exists.
>>
>> Cheers
>>
>> robert

>
> It's actually embedding that I'm using right now. I am using Ruby as a
> script language for a code editor to perform operations on text etc.
> There is a script which is loaded when the program loads which
> contains
> some classes defined by the user for example. I would like to be able
> to
> reload this script without having warnings about constants, having
> classes mixed together if the user changed the name of a function
> between the loadings or still having the same global variables.
>
> Remi Gillig.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You will not be able to reset the access - can't reset. jc MCAD 0 12-09-2007 08:58 PM
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... \A_Michigan_User\ ASP .Net 2 08-21-2006 02:13 PM
CISCO 7XX / 761 password reset or reset to factory defaults Philipp Flesch Cisco 3 06-18-2006 07:47 PM
What is the state of state machine after power-up without reset conditions Weng Tianxiang VHDL 7 11-25-2003 06:24 PM
Reset whole config of a Cisco Catalyst 3548 XL switch Syn Cisco 1 10-17-2003 12:59 PM



Advertisments