gpt4 book ai didi

ruby - 为什么添加 c 扩展的 ruby​​ 代码不起作用?

转载 作者:数据小太阳 更新时间:2023-10-29 07:53:22 24 4
gpt4 key购买 nike

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

在执行这段 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
^

最佳答案

您正在使用该 gem 的某个已废弃的旧版本。从来没有 SeattleRb 团队创建并称为 RubyInline 的版本.检查一下。

关于ruby - 为什么添加 c 扩展的 ruby​​ 代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15334621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com