Wrap text
Report abuse
module MetaSkills
def attribute_accessor(name)
attribute_reader(name)
attribute_writer(name)
end
def attribute_reader(name)
define_method(name) do
instance_variable_get "@#{name}"
end
end
def attribute_writer(name)
define_method "#{name}=" do |value|
instance_variable_set "@#{name}", value
end
end
end
Class.instance_eval do
include MetaSkills
end
class MyClass
attribute_accessor :foo
end
o = MyClass.new
o.foo
o.foo = 'bar'
o