Created
October 14, 2010 02:09
-
-
Save lfborjas/625416 to your computer and use it in GitHub Desktop.
An interpreter for one-liner java expressions. Useful for testing stuff without writing mains; based on beanshell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #based on jruby | |
| require "java" | |
| #copied the beanshell jar because jruby can't seem to be aware of the classpath | |
| require "./bsh-2.0b4.jar" | |
| #cf. http://bogojoker.com/readline/ | |
| require 'readline' | |
| #based on this: http://blogs.sun.com/coolstuff/entry/using_java_classes_in_jruby | |
| include_class Java::bsh.Interpreter | |
| i = Interpreter.new | |
| begin | |
| #I should rescue from evalErrors, but meh, not now | |
| while instr = Readline.readline('> ', true) | |
| puts "=> #{i.eval instr}" | |
| end | |
| rescue Interrupt => e | |
| system 'stty', stty_save | |
| exit | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment