JRuby as Interactive Java Shell

Martin Dittus · 2007-07-06 · tools · write a comment

Get the JRuby Console, and then do stuff like this:

irb(main):001:0> require 'java'
=> true
irb(main):002:0> p = java.util.regex.Pattern.compile("/music/[^/]+/\\+images/[^/?]+?(?:\\?.*)?")
=> #<#:0x5efe34 @java_object=/music/[^/]+/\+images/[^/?]+?(?:\?.*)?>
irb(main):003:0> p.matcher("/music/Christopher+Willits/+images/?").matches
=> false
irb(main):004:0> p.matcher("/music/Christopher+Willits/+images?").matches
=> false
irb(main):005:0> p.matcher("/music/Christopher+Willits/+images/").matches
=> false
irb(main):006:0> p.matcher("/music/Christopher+Willits/+images/34523").matches
=> true

Awesome! I've been waiting years for a convenient interactive Java shell -- and not to run the language, but to interactively test behaviour of library features under certain conditions. Don't want to write & compile a new class just because I want to check something out.


Next article:

Previous article:

Recent articles:

Comments

Comments are closed. You can contact me instead.