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

Version Path
rhodes-3.2.2 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.2.beta platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.1 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.9 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.8 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.7 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.6 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.5 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.4 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.2 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.2.0.beta.1 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.1 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.1.beta platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0.beta.5 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0.beta.4 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0.beta.3 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0.beta.2 platform/shared/xruby/src/com/xruby/Example.java
rhodes-3.1.0.beta.1 platform/shared/xruby/src/com/xruby/Example.java