Utility methods for modifying a ruby object’s eigenclass/metaclass
gem install eigenclass
This gem allows you to define class level accessors, readers, and writers
class SomeClass eattr_accessor :test_accessor eattr_reader :test_reader eattr_writer :test_writer end SomeClass.test_accessor = 'testing'
You can also dynamically create class methods
SomeClass.class_eval do define_class_method 'test_class_method' do 'test' end end SomeClass.test_class_method # returns 'test'
You can even evaluate a block of code inside the scope of an object’s eigenclass
SomeClass.eigenclass_eval do attr_accessor :test_eigenclass_eval end SomeClass.test_eigenclass_eval = true
A reference to any object’s eigenclass can be accessed by calling
SomeObject.eigenclass
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Problems, comments, and suggestions all welcome: [email protected]