Skip to content

Instantly share code, notes, and snippets.

@tofumatt
Created August 31, 2010 00:41
Show Gist options
  • Save tofumatt/558318 to your computer and use it in GitHub Desktop.
Save tofumatt/558318 to your computer and use it in GitHub Desktop.
Define methods based on database calls? Bwahahaha awful.
# Define available role checks as methods.
def after_initialize
# Define the available role check methods for each User.
(@@roles ||= Role.all).each do |role|
self.class.send(:define_method, :"#{role.slug}?") do
is = false
roles.each do |r|
is = true if r.id == Role.const_get(role.slug.upcase)
end
is
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment