delegator.cr
Delegator
Decorates an object and delegates missing methods to it. Based on the code in this gist by @decors
Installation
Add this to your application's shard.yml
:
dependencies:
delegator:
github: Schniz/delegator.cr
Usage
require "delegator"
# Given a class
class Person
property name
def initialize(@name); end
end
# Create a subclass of Delegator
class PersonDelegator < Delegator(Person)
def greet
"Hello, #{name}!"
end
end
# Use it to decorate objects!
joe = Person.new("Joe")
PersonDelegator.delegate(joe).greet # "Hello Joe!"
Contributing
- Fork it ( https://github.com/Schniz/delegator.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Schniz Gal Schlezinger - creator, maintainer
Repository
delegator.cr
Owner
Statistic
- 1
- 0
- 0
- 2
- 0
- about 7 years ago
- October 21, 2017
License
MIT License
Links
Synced at
Mon, 18 Nov 2024 03:24:05 GMT
Languages