Created
January 18, 2013 21:21
-
-
Save jcalvert/4568659 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
module MethodPair | |
def method_accessor(var, &block) | |
define_method("set_#{var}",block) | |
define_method(var) do | |
var_name = var.to_s.gsub(/\?/,'') | |
insvar = instance_variable_get("@#{var_name}") | |
unless insvar | |
insvar = self.send("set_#{var}") | |
instance_variable_set("@#{var_name}", insvar) | |
end | |
insvar | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment