以前说,用module给class加singleton方法,和extend到类include到类的instance
现在看看这个
module Prober
def probe_invoke(type, data = {})
p = Probe.new({:probe_type => type.to_s,
:data => data.to_json, :probe_status => 0, :retries => 0})
p.save
end
end
掉的时候
require 'prober'
include Prober
probe_invoke("send_sms", sms_text)
module Prober
def Prober.probe_invoke(type, data = {})
p = Probe.new({:probe_type => type.to_s,
:data => data.to_json, :probe_status => 0, :retries => 0})
p.save
end
end
Prober.probe_invoke("send_sms", sms_text)
module Prober
class << self
def probe_invoke(type, data = {})
p = Probe.new({:probe_type => type.to_s,
:data => data.to_json, :probe_status => 0, :retries => 0})
p.save
end
# more module instance methods ...
end
end