我跟着this tutorial創建了一個簡單的命令行gem,現在我想用raad擴展功能。在cli gem中使用raad和eventmachine
斌/ zerp:目前我有教程以下後,進行了如下修改
#!/usr/bin/env ruby
require 'zerp'
class Zerp
def start
Raad::Logger.debug 'zerp started'
EventMachine.run do
EventMachine.add_periodic_timer(1) do
Raad::Logger.info 'zerp is running'
end
end
end
def stop
EventMachine.stop
Raad::Logger.debug 'zerp stopped'
end
end
的lib/zerp.rb:
require 'zerp/version'
require 'eventmachine'
require 'raad'
module Zerp
end
當我從客戶端運行命令行我得到以下錯誤。
[email protected]:~/git/zerp :) zerp
/home/user/.local/lib/ry/rubies/1.9.3-p194/lib/ruby/gems/1.9.1/gems/zerp-0.0.1/bin/zerp:5:in `<top (required)>': Zerp is not a class (TypeError)
from /home/user/.local/lib/ry/current/bin/zerp:23:in `load'
from /home/user/.local/lib/ry/current/bin/zerp:23:in `<main>'
[email protected]:~/git/zerp :(
什麼是正確的方法來得到這個工作?
我只會用'Process.daemon'和'optparse'去代替'raad'。 – pkhamre 2012-07-12 20:42:46