1

How can I take a regular Ruby script I have in my text editor (and saved to a file in the FS)

and then evaluate it inside an already-running Ruby process with its existing objects?

I should be able to run my script, with the ObjectSpace of the existing Ruby process accessible to it, then terminate my script while the ruby process continues to run, edit my script, and re-run it in the same Ruby process, again and again.

Is there a common computer science term that refers to this?

0

3 Answers 3

2

You'll have to be a bit more specific about what triggers the script being re-run. It will however boil down to calling eval(IO.read("scriptname.rb")) or something similar.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, I guess it is pretty simple once I get straight what behavior I want.
1

REPL is the computer science term that refers to what you're looking for

see http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop

Comments

0

You can use GDB to debug any process including a ruby process, this will let you execute any C function, and as we're trying to execute ruby code from string you can use rb_eval_string_protect function to execute any ruby code you want.

I got this solution from this article https://spin.atomicobject.com/2013/08/19/debug-ruby-processes/ The author describes the method with an example of redirecting the standard output to a file, but you can use it for any other purposes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.