I have seen the run_once method in some code like
run_once do
[:hello, :core, :gems, :plugins, :lib, :initializers, :routes, :app, :helpers].each do |f|
require File.join_from_here('mack', 'boot', "#{f}.rb")
end
end
I found it in Kernel, but not sure what it does… something to do with running once I guess…
Assuming it is the Mack Facets run_once method we’re talking about, here is its source:
You would call the method with no arguments but passing a block.
run_oncetakes the first entry from the call stack (caller.first) to determine the point in code from which it is being called. It will only yield to the block ifrun_oncehasn’t yet been called from this call point (tracked by keeping the list of call points in the global array$__already_run_block)e.g. it could be used along these lines: