Created
July 24, 2012 16:01
-
-
Save jcasimir/3170863 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Settings | |
def self.included(source) | |
source.class_eval do | |
def self.setting(*args) | |
args.each do |setting| | |
attr_accessor setting | |
define_method "#{setting}_on" do | |
self.send("#{setting}=", true) | |
end | |
define_method "#{setting}_off" do | |
self.send("#{setting}=", false) | |
end | |
define_method "#{setting}_on?" do | |
!!self.send(setting) | |
end | |
define_method "#{setting}_off?" do | |
!self.send(setting) | |
end | |
end | |
end | |
end | |
end | |
end | |
class MattConfig | |
include Settings | |
setting :power | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment