Skip to content

Utility methods for modifying a ruby object's eigenclass/metaclass

License

Notifications You must be signed in to change notification settings

cloudcrowd/eigenclass

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eigenclass

Utility methods for modifying a ruby object’s eigenclass/metaclass

Installation

gem install eigenclass

Usage

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

Note on Patches/Pull Requests

  • 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.

Contact

Problems, comments, and suggestions all welcome: [email protected]

About

Utility methods for modifying a ruby object's eigenclass/metaclass

Resources

License

Stars

Watchers

Forks

Packages

No packages published