Is there a Ruby REPL in Ruby? [closed]

2019-07-27 00:19发布

Ok, the title doesn't really say very much, but I couldn't think of anything better.

I'm looking for (J)Ruby library that provides a headless REPL, so to speak. Basically, I want it to take a String, and then tell me if it expects more input, otherwise eval the input so far and give me either the result or an error message.

This is for running a Ruby REPL inside a game, so I'm specifically not looking for irb.

1条回答
聊天终结者
2楼-- · 2019-07-27 00:23

Check out Debugger. It isn't 'live' like a REPL but you can stop code at any given point in your execution and open up irb with the current scope to check/change variables, run methods, etc. Not as fancy as a REPl, but it still may work for your needs.

To install:

gem install debugger

Then in your ruby code:

# ...
debugger
#...

This will open up a prompt that looks like this:

查看更多
登录 后发表回答