Skip to content

Instantly share code, notes, and snippets.

@danramteke
Created April 16, 2011 15:09
Show Gist options
  • Save danramteke/923177 to your computer and use it in GitHub Desktop.
Save danramteke/923177 to your computer and use it in GitHub Desktop.
class Object
def self.my_attr_accessor variable
class_eval("def #{variable}= val; @#{variable} = val; end")
class_eval("def #{variable}; @#{variable}; end")
end
end
require 'attr_accessor'
require 'test/unit'
class A
my_attr_accessor "points"
end
class AttrAccessorTest < Test::Unit::TestCase
def test_it_works
a = A.new
a.points = 5
assert_equal 5, a.points
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment