Search code examples
rubyirbpryterminal-emulator

How can I embed Ruby shell (or pry) emulator into a website?


I'd like to add Ruby shell (irb) or pry emulator into a website like Try Ruby. How can I do it?

EDIT: TryRuby was created with jquery-console as I understood from its source code but I wonder another way (especially in Ruby, otherwise JavaScript) to do it.

ANOTHER EDIT: I've voted to close my own question as;

Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

I won't delete it and I will be very proud to ask questions forever!


Solution

  • Not at all a trivial task.


    One approach would be to have the browser send requests to the server. The downsides are - you need to manage the server, you have to implement the front end communication with the server, etc. normal webapp stuff. The biggest problem - there is no functional sandbox for cRuby out there. If you need any degree of security measures - you have to implement them on your own.

    A place for inspiration - the rails browser console for development mode.


    Another approach is to use Opal and keep everything on the user side. The huge issue there - while it tries to, Opal is not an exact implementation of the language (it being defined by the cRuby implementation). So if complete "realism" is something that you need - this solution is not applicable.

    A place for inspiration - the opal site itself has a section that lets you try out Ruby code in the browser.