Skip to content

Instantly share code, notes, and snippets.

@lfborjas
Created October 14, 2010 02:09
Show Gist options
  • Select an option

  • Save lfborjas/625416 to your computer and use it in GitHub Desktop.

Select an option

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
#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