Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created January 18, 2013 21:21
Show Gist options
  • Save jcalvert/4568659 to your computer and use it in GitHub Desktop.
Save jcalvert/4568659 to your computer and use it in GitHub Desktop.
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