QCon 2007 Notes: JRuby

Rob Harrop, Java and Ruby: Practical Techniques for Using JRuby

  • RH plugged The Ruby Way as a good book for learners from Java, very task-focused
  • JRuby can put a really nice API around the rather clunky JMX API, or simpler builders for Swing panels: in fact, a neat general use for JRuby is to create DSLs to wrap painful Java APIs.
  • RH noted he had also seen absolute disaster when people tried to DSL their entire domain at once
  • Three ways of integrating JRuby code with Java:
    • BSF (RH: simple, but not particularly powerful)
    • The JRuby API (RH: note entirely clear or documented)
    • Spring from 2.0.2 fully wraps JRuby; in spring.xml you just identify the bean with the lang:jruby element instead of the bean element. (You can also include a refresh-check-delay attribute for dynamically reloading scripts
  • Some really neat advantages to JRuby
    • Operator overloading
    • Blocks
      • With JRuby DSLs we can structurally encapsulate really complex conditional logic and keep it in simple rule blocks
    • method_missing
    • Dynamic extension (we can change classes and methods on the fly)
      • If that’s too scary, you can also take a single instance of a class and add methods only to that object on the fly
  • Note that the Groovy integration with Java is a lot nicer and tighter than JRuby’s, and that error propagation from JRuby to Java is “a whole new world of awful”

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply