我今天早上第一次开始使用赛璐珞宝石。我正在关注这个Railscasts tutorial并试图解决问题。
我有一个名为"SomeClass"
的类,它只有一个方法。这是代码:
require 'celluloid'
class SomeClass
include Celluloid
def initialize(name)
@name = name
end
def assholify()
puts "#{@name} has become an ASSHOLE."
end
end
当我创建类的新实例并调用它的方法(使用bang即"assholify!"
)时,我收到undefined method 'assholify!'
错误。但Celluloid应该在用一声巨响调用时异步触发该方法。所以这就是我如何调用方法:
names = ['John', 'Tom', 'Harry']
names.each do |name|
n = SomeClass.new name
n.assholify!
end
以下是错误的完整回溯:
I, [2016-09-09T11:28:02.488618 #3682] INFO -- : Celluloid 0.17.3 is running in BACKPORTED mode. [ http://git.io/vJf3J ]
/home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:42:in `rescue in check': undefined method `assholify!' for #<SomeClass:0x10897dc> (NoMethodError)
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:39:in `check'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:26:in `dispatch'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/call/sync.rb:16:in `dispatch'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:50:in `block in dispatch'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:76:in `block in task'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/actor.rb:339:in `block in task'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/task.rb:44:in `block in initialize'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/task/fibered.rb:14:in `block in create'
from (celluloid):0:in `remote procedure call'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/call/sync.rb:45:in `value'
from /home/railsdev/.rvm/gems/ruby-2.3.1/gems/celluloid-0.17.3/lib/celluloid/proxy/sync.rb:22:in `method_missing'
from some_class.rb:18:in `block in <main>'
from some_class.rb:16:in `each'
from some_class.rb:16:in `<main>'
为什么我收到此错误?这是调用函数的正确方法吗?另外我如何摆脱Celluloid 0.17.3 is running in BACKPORTED mode.
警告?
答案 0 :(得分:1)
发生undefined method
错误是因为在最近版本的赛璐珞宝石中没有调用actor方法。相反,您可以调用这样的方法:n.async.assholify
。所以代码应该是这样的:
names = ['John', 'Tom', 'Harry']
names.each do |name|
n = SomeClass.new name
n.async.assholify # Instead of "n.assholify!"
end
<小时/> 对于
"Celluloid 0.17.0 is running in BACKPORTED mode"
警告,请查看this wiki。 Backported Mode是默认值,在有限的时间内。如果您使用require 'celluloid/current'
代替require 'celluloid'
,则不应看到此警告。