I stumbled onto it while researching hot code reloading in ruby.
I stumbled onto it while researching hot code reloading in ruby.
With the hot code reloading features in some JVMs now, it'd be interesting to see if there's any case for it in JRuby one day.
http://www.rubyinside.com/hijack-get-a-live-irb-prompt-for-a...
This ranks higher than the github repo while searching for "ruby attach running process." hnsearch showed the same article being submitted about 2 years ago, with not much interest showed.
I was a bit surprised. I was searching for HN thread as I was expecting some useful discussion, but found none. I assumed this is the kind of topic which would interest HN crowd, but looks like that isn't the case.
(I did the first HN post about TechCrunch's new design, 1 point.. later one went big :-) I've even done the first post of items on the 37signals blog and Mixergy that have sat at 1. All depends who's browsing the 'new' page in that 30 minute window!)
1. Find a way to attach to a running process. Either leave a socket open, as done in twisted manhole; or directly attach to running process.
2. Once you are connected, if you get a repl in the same address space, you can redefine methods, classes etc.
See the example in the github README where he redefines a method.
3. Redefining running code is generally considered a bad idea. The usefulness of a repl to a running process is generally the analysis - you can monitor memory usage etc without changing anything.
4. When you do change things, it's mostly small changes viz. log calls to a particular method. Dummy example:
class Foo
alias_method :orig_handler, :handler
def handler
log_request
orig_handler
end
end
5. The way erlang does it is it automatically reloads if the physical file changes. It's a bit hard to implement in Python/Ruby because it isn't supported out of the box, and figuring out the module dependency isn't reliable(if file a changes, how many files were depending on it?). The general approach is to restart the server.6. But regardless, the remote repl gives you analysis and selective reloading which is also useful.