Alexey
Alexey

Reputation: 9447

Combination of breakpoint and irb (REPL)

Sometimes I want to experiment using IRB with some objects, but it's might be not that easy to reproduce the state and context that I need. Consider you want to play with syntax of an expression inside RSPec. So I want to implement something like this:

  1. inside of code of an ruby application that I currently developing I invoke function eval_server
  2. it creates server socket and listens for connections
  3. I start some tool similar to IRB (let's call it eval_client - it should be implemented)
  4. it creates client socket and connects to eval_server
  5. I type some ruby expression in eval_client
  6. eval_client sends it to eval_server
  7. eval_server evaluates the expression in context of the object where it was invoked, serializes the result or exception (using .inspect for example), and sends it back to eval_client
  8. eval_client displays the result

...

The question is: if there similar tool already implemented? If not, are there some gems that might help me to implement it?

I know it might look like debugger. But I would prefer not to start rails server with debugger. I just want to add one like in code and have IRB in context of that line at next request.

update:

so according to the answer:

eval_client = pry-remote

eval_server = binding.remote_pry

https://github.com/mon-ouie/pry-remote

Upvotes: 2

Views: 226

Answers (1)

horseyguy
horseyguy

Reputation: 29895

A Pry plugin called pry-remote can do this:

see: https://github.com/pry/pry/wiki/Remote-sessions

Upvotes: 1

Related Questions