我試圖在ruby中實現懶惰的方法執行。比方說,我有哪些不應該調用後立即執行的兩項方法的類檢測方法調用
class Foo
lazy_evaluate :bar, :baz
def bar(string)
puts string
end
def baz(hash)
puts hash.inspect
end
end
f = Foo.new
f.bar('hello world') => nil
f.baz(hello: :world) => nil
f.run_lazy_methods =>
'hello world'
'{:hello=>:world}'
我wan't使用這在我的寶石http://pastie.org/5137463
我要求知道如何實現這一行爲
看看延遲工作,Sidekiq或任何其他異步排隊寶石。 – meagar
伊莫在這種特殊情況下我不能使用延遲工作和其他後臺工作人員。 http://pastie.org/5137463 – Lewy
你可能想看看這個線程:http://stackoverflow.com/questions/9371875/task-future-in-ruby –