Closed no6v closed 12 years ago
I found that :eval onces.size is getting bigger and bigger. So, exchange the order of _init and _once, and clear onces every time.
Another approach: freezing onces after _once, and ignoring passed block via once if onces is frozen. Which do you like?
diff --git a/lib/earthquake/core.rb b/lib/earthquake/core.rb index a3a4c7d..4153be3 100644 --- a/lib/earthquake/core.rb +++ b/lib/earthquake/core.rb @@ -24,11 +24,13 @@ module Earthquake end def once(&block) + return if onces.frozen? onces << block end def _once onces.each { |block| class_eval(&block) } + onces.freeze end def _init
Oops, this patch breaks once blocks in plugins. The "Another approach" is right way. I'll do pull request again.
I found that :eval onces.size is getting bigger and bigger. So, exchange the order of _init and _once, and clear onces every time.
Another approach: freezing onces after _once, and ignoring passed block via once if onces is frozen. Which do you like?