2013-03-11 61 views
3
在執行這一塊的Ruby代碼我得到很多的錯誤
require "rubygems" 
require "inline" 

class Primes 
    inline do |builder| 
    builder.c ' 
    int prime(int num) { 
    if (num == 2){ return 1;} 
    if (num %2 == 0) {return 0;} 
    int i = 3; 
    while(i * i <= num) 
    { 
      if (num % i==0) 
      { 
      return 0; 
      } 
      i = i+2; 
    } 
    return 1; 
    }' 
    end 
end 

p = Primes.new 

for num in 2..10_000 do 
    is_prime = p.prime(num) 
    if is_prime == 1 
     puts "#{num} is a prime number" 
    else 
     puts "#{num} equals #{is_prime} * #{num/is_prime}" 
    end 
end 

...爲什麼添加c擴展名的ruby代碼不起作用?

/.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:96: warning: else without rescue is useless 
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:108: warning: else without rescue is useless 
.rvm/rubies/ruby-1.9.3-p362/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':/.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:93: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n' (SyntaxError) 
      when nil: @position = length-1 
        ^
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:94: syntax error, unexpected keyword_when, expecting keyword_end 
      when 0: @position = length-1 if @cycle 
       ^
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:105: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n' 
      when nil: @position = length-1 
        ^
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:106: syntax error, unexpected keyword_when, expecting keyword_end 
      when length-1: @position = 0 if @cycle 
       ^
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:106: syntax error, unexpected ':', expecting keyword_end 
      when length-1: @position = 0 if @cycle 
         ^
.rvm/gems/ruby-1.9.3-p362/gems/inline-0.1.0/lib/inline/history_buffer.rb:128: syntax error, unexpected keyword_end, expecting $end 
    end 
    ^

回答

5

您使用的是一些舊版本被拋棄創業板的。從來沒有由SeattleRb團隊創建的版本,並稱爲RubyInline。看一下這個。

+0

感謝ŁukaszNiemier的幫助.... – sanjee 2013-03-11 10:52:33

+0

您可以通過在選票下使用勾號來接受答案。 – Hauleth 2013-09-14 22:13:58

相關問題