Sha256: 045bd7a0043946b898e6311c351e52bb77d965aacf170d51a394300e022c4cfa
Contents?: true
Size: 1.16 KB
Versions: 135
Compression:
Stored size: 1.16 KB
Contents
/** * Copyright 2005-2007 Xue Yong Zhi * Distributed under the BSD License */ package com.xruby; import com.xruby.compiler.*; import com.xruby.compiler.codegen.*; import com.xruby.runtime.lang.*; //This file serves as an example of running Ruby program in Java public class Example { public static void main(String[] args) throws Exception { String program_text = "def fibonacci(n)\n" + " if n == 1 or n == 0\n" + " n\n" + " else\n" + " fibonacci(n - 1) + fibonacci(n - 2)\n" + " end \n" + "end\n" + "\n" + "start_time = Time.new.to_f\n" + "puts start_time\n" + "puts fibonacci(30)\n" + "end_time = Time.now.to_f\n" + "puts start_time\n" + "puts end_time - start_time"; RubyCompiler compiler = new RubyCompiler(); CompilationResults codes = compiler.compileString(program_text); RubyProgram p = codes.getRubyProgram(); RubyRuntime.init(args); p.invoke(); RubyRuntime.fini(); } }
Version data entries
135 entries across 135 versions & 2 rubygems