Created
August 31, 2010 00:41
-
-
Save tofumatt/558318 to your computer and use it in GitHub Desktop.
Define methods based on database calls? Bwahahaha awful.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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