RubyFluxRuby代碼轉(zhuǎn)Java的工具
RubyFlux 是一個編譯器,用來將 Ruby 代碼轉(zhuǎn)成對應的 Java 代碼,并可在 JVM 中運行,而無需其他運行環(huán)境的要求。
每個 Ruby 類生成一個對應的 Java 文件。
使用示例:
# The file we want to compile
$ cat fib.rb
def fib(a)
if a < 2
a
else
fib(a - 1) + fib(a - 2)
end
end
puts fib(40)
# First need to build the compiler's jar
$ mvn package
<maven noise>
# Provide the target file to 'rake run'.
#
# The Ruby sources are translated to .java and all support code is copied out
# of RubyFlux for the compilation step. That source is then compiled and run.
# to compile
$ rake run[fib.rb]
jruby -I target:src/main/ruby src/main/ruby/ruby_flux.rb fib.rb
javac fib.java
java fib
102334155評論
圖片
表情
