Created
July 24, 2009 00:21
-
-
Save joshsusser/153758 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
### meta magic boolean attributes | |
def self.attr_boolean(attr_name) | |
class_eval(<<-CODE, __FILE__, __LINE__) | |
def #{attr_name}=(#{attr_name}) | |
@#{attr_name} = !!(/^1|true$/i =~ #{attr_name}) # yes, we need a boolean | |
end | |
def #{attr_name} | |
@#{attr_name} | |
end | |
alias_method :#{attr_name}?, :#{attr_name} | |
CODE | |
end | |
attr_boolean :is_awesome | |
attr_boolean :has_mutant_powers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment