RubyInline允许你在ruby代码中直接编写c/c++代码,还会有性能问题吗?
安装方法:sudo gem install RubyInline
示例代码:
class MyTest
def factorial(n)
f = 1
n.downto(2) { |x| f *= x }
f
end
inline do |builder|
builder.c "
long factorial_c(int max) {
int i=max, result=1;
while (i >= 2) { result *= i--; }
return result;
}"
end
end
在irb中输入 [code]require 'scrubyt'[/code] 出现以下错误信息: [code] Gem::Exception: can't activate RubyInline (= 3.6.3), already activated RubyInline-3.6.6] from /usr/lib/ruby/1.8/rubygems.rb:254:in `activate' fr
装好 scruby 后第一次使用遇到一个错误: site_ruby/1.8/rubygems.rb:246:in `activate': can't activate RubyInline (= 3.6.3), already activated RubyInline-3.6.6] (Gem::Exception) GOOGLE了一下,找到了两种方法: 1.使用gem uninstall Ruby