Skip to content

Instantly share code, notes, and snippets.

@gkop
Created October 24, 2012 19:23
Show Gist options
  • Save gkop/3948243 to your computer and use it in GitHub Desktop.
Save gkop/3948243 to your computer and use it in GitHub Desktop.
Best practice for methods used only during pre-initialization?
# This simple solution permanently adds a method on Object that
# will never be used outside this file.
def compile_asset?(path)
# ... lots of complicated logic ...
# returns boolean
end
Foo::Application.configure do
...
config.assets.precompile = [ method(:compile_asset?).to_proc ]
end
# One way to keep things clean
class <<Foo::Application
def compile_asset?(path)
# ... lots of complicated logic ...
# returns boolean
end
end
Foo::Application.configure do
...
config.assets.precompile = [ method(:compile_asset?).to_proc ]
end
class <<Foo::Application
remove_method :compile_asset?
end
# What's a more elegant way?
@rahearn
Copy link

rahearn commented Oct 24, 2012

I'm probably wrap them all in a module that sticks around but then doesn't leak out into Object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment