Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created May 10, 2011 12:01
Show Gist options
  • Save tcrayford/964346 to your computer and use it in GitHub Desktop.
Save tcrayford/964346 to your computer and use it in GitHub Desktop.
class MyObject
def self.my_attr_reader(*args)
args.each do |method_name|
class_eval do
define_method(method_name) do
self.instance_variable_get("@#{method_name}")
end
end
end
end
def self.my_attr_accessor(*args)
args.each do |method_name|
class_eval do
define_method(method_name) do
self.instance_variable_get("@#{method_name}")
end
define_method("#{method_name}=") do |arg|
self.instance_variable_set("@#{method_name}", arg)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment