https://github.com/yegor256/decoor
True Object-Oriented Decorator for either an Object or a Class
https://github.com/yegor256/decoor
decorator decorator-pattern decorators oop ruby
Last synced: 4 months ago
JSON representation
True Object-Oriented Decorator for either an Object or a Class
- Host: GitHub
- URL: https://github.com/yegor256/decoor
- Owner: yegor256
- License: mit
- Created: 2024-06-21T08:01:24.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-17T08:42:21.000Z (10 months ago)
- Last Synced: 2024-09-17T13:06:02.651Z (10 months ago)
- Topics: decorator, decorator-pattern, decorators, oop, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/decoor
- Size: 40 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# True Object-Oriented Decorator
[](http://www.rultor.com/p/yegor256/decoor)
[](https://www.jetbrains.com/ruby/)[](https://github.com/yegor256/decoor/actions/workflows/rake.yml)
[](http://www.0pdd.com/p?name=yegor256/decoor)
[](http://badge.fury.io/rb/decoor)
[](https://codecov.io/github/yegor256/decoor?branch=master)
[](http://rubydoc.info/github/yegor256/decoor/master/frames)
[](https://hitsofcode.com/view/github/yegor256/decoor)
[](https://github.com/yegor256/decoor/blob/master/LICENSE.txt)Let's say, you have an object that you want to decorate, thus
adding new attributes and methods to it. Here is how:```ruby
require 'decoor'
s = ' Jeff Lebowski '
d = decoor(s, br: ' ') do
def parts
@origin.strip.split(@br)
end
end
assert(d.parts == ['Jeff', 'Lebowski'])
```You may also turn an existing class into a decorator:
```ruby
require 'decoor'
class MyString
def initialize(s, br)
@s = s
@br = br
end
decoor(:s)
def parts
@origin.strip.split(@br)
end
end
d = MyString.new('Jeff Lebowski')
assert(d.parts == ['Jeff', 'Lebowski'])
```That's it.
## How to contribute
Read
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have
[Ruby](https://www.ruby-lang.org/en/) 3.2+ and
[Bundler](https://bundler.io/) installed. Then:```bash
bundle update
bundle exec rake
```If it's clean and you don't see any error messages, submit your pull request.