Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bltavares/delegate-class
Wrap a whole class (including classes methods) into a delegate class
https://github.com/bltavares/delegate-class
Last synced: 28 days ago
JSON representation
Wrap a whole class (including classes methods) into a delegate class
- Host: GitHub
- URL: https://github.com/bltavares/delegate-class
- Owner: bltavares
- Created: 2012-01-27T01:53:21.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-02-02T00:54:30.000Z (almost 13 years ago)
- Last Synced: 2024-04-14T19:36:05.850Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Delegate-class
Using the default ruby delegate library, this gem is used to wrap the class _AND_ instance methods of another class.
(_Though I still don't know the real usage of it_)You may want to use it like this:
##Usage
I found it can be used on these situations.
Lets say you are using Rails and has the model:
```ruby
class User < ActiveRecord::Base
end```
And then you have an author delegator class, modified to make things like _#form_for_
```ruby
require "delegate"class Author < SimpleDelegator
def class
__getojb__.class
enddef bookmates
User.find(1)
enddef name
super + "!"
end
end```
IMO, there are two bad things in these code:
1. Redefine class
2. Referencing the class you should be delegatingYou may change it to:
```ruby
require "delegate/class"class Author < ClassDelegator(User)
def bookmates
self.class.find(1)
enddef name
super + "!"
end
end```
Now, you are delegating the instance and class methods to the wrapped class/object
## Instalation
[![Build Status](https://secure.travis-ci.org/bltavares/delegate-class.png)](http://travis-ci.org/bltavares/delegate-class)
It's is simple.
Add to your gem file
```ruby
gem "delegate/class"
```And run
```bash
bundle install
```Hope you like it (: