Using Ruboto IRB to jump start development

rscottm edited this page Jan 3, 2013 · 7 revisions
Clone this wiki locally

Why use Ruboto IRB?

  • If you have an Android device, you can start playing with Android & Ruboto without setting up a development environment.

  • If you are learning Android or learning a new portion of the Android API, you can experiment with small amounts of code to get a feel for how it works.

  • If you're starting a new app, you can develop and rapidly refine your code without recompiling and redeploying an apk.

Getting Code into Ruboto IRB

For Ruboto IRB to do any good, you'll need code on the device. There are multiple ways to accomplish this:

  • Enter code directly into the IRB text field or into the editor. This method is limited on any device by the quality of your keyboard (and selection tool).

  • Push scripts to the device. This requires some mechanism for pushing the scripts (e.g., adb, Wifi File Explorer, etc.).

  • Pull scripts onto the device. Again, this requires a mechanism. This can be a simple script that pulls scripts from a remote location (e.g., Dropbox, website).

  • By far the most efficient solution is to use the demo-irb-server.rb script to interact directly with the device.


Running demo-irb-server.rb starts up a web server on the device. If the device is attached to a wifi network, then browsing to the device's address (+ port 8005). The server provides several features:

  • Home(eval): Evaluate a chunk of code and receive any output along with the return value.

  • Scripts: Create, edit, save, and evaluate scripts on the device.

  • History: Access to the last 10 pieces of code evaluated.


  • Syntax highlighting is provided through CodeMirror

  • You can select to evaluate code on its own thread or on the UI thread.

  • All output sent to stdout will be returned. If output occurs after the page returns (e.g., launching a new activity that later prints something to stdout), it will be returned at the top of the next batch of output.

Using Ruboto IRB on an emulator

If you've set up a standard Android development environment, you can run Ruboto IRB on an emulator.

  • Instead of downloading Ruboto IRB from the Google Play Store, you will need to download the latest apk from Github.

  • You can use adb push to push scripts to the emulator.

  • If you run demo-irb-server.rb, you can use adb forward tcp:8005 tcp:8005 to set up forwarding. Then navigate to localhost:8005 to access the web server. Note: This also works if you're connected to a device and wan to use adb instead of a wifi connection.


Everything you do in Ruboto IRB happens inside of a single JRuby ScriptingContainer. Currently, the only way to reset the ScriptingContainer is to force the app to terminate and restart it. Beware of conflicts that might occur if you run more than one script. For example, if you run demo-irb-server.rb, it replaces stdout with a StringIO. If you run a script that needs to manipulate stdout, it will interfere with the operation of demo-irb-server.rb.