SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 190 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

Amazing!
To give you a glimpse of how you can call methods on objects you get back and things
like this, this snippet shows how to get hold of a JRuby object for a number, and calling a Ruby
method on that object called "succ", which returns the next value for the integer:
IRubyObject num = JavaEmbedUtils.javaToRuby(runtime, 27);
IRubyObject num2 = num.callMethod(runtime.getCurrentContext(), "succ");
CHAPTER 6 ?–  JAVA INTEGRATION 112
When this code is executed in a relevant context, num2 will contain a Ruby Fixnum with the
value 28. You probably understand why I don??™t recommend working directly with this interface.
It works well for implementing libraries around the engine, but it??™s not that useful for
application development.
Bean Scripting Framework
Bean Scripting Framework, or BSF for short, is an open source project hosted by Apache
Jakarta. It was originally developed by IBM and later open sourced. The purpose is to make
different so-called scripting engines available to a Java program with a language-agnostic
interface. That means the code looks almost exactly the same, whether you are working with
JavaScript, TCL, Python, Ruby, or any other language with BSF bindings. You need to have
BSF and Commons Logging on your CLASSPATH for this example to work.
package c6;
import org.apache.bsf.BSFManager;
public class JRubyBSF {
public static void main(String[] args) throws Exception {
BSFManager.registerScriptingEngine("ruby",
"org.jruby.


Pages:
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202