Created
March 10, 2010 01:37
-
-
Save dougo-chris/327373 to your computer and use it in GitHub Desktop.
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
# I want to define access levels with: | |
# ActionController::Base.define_access_level(:reporter, 9) | |
module Dougo | |
module MyExtensionToClass | |
def self.included(base) | |
base.class_eval do | |
extend ClassMethods | |
end | |
end | |
module ClassMethods | |
def define_access_level name, access_level | |
# class methods | |
(class << self; self end).instance_eval do | |
define_method "access_level_#{name}" do | |
return access_level | |
end | |
end | |
# instance methods | |
define_method "logged_in_as_#{name}?" do | |
self.access_level == access_level | |
end | |
self.send :helper_method, "logged_in_as_#{name}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment