https://github.com/yegor256/tacky
Primitive Object Memoization for Ruby
https://github.com/yegor256/tacky
cache memoization ruby-gem
Last synced: 10 months ago
JSON representation
Primitive Object Memoization for Ruby
- Host: GitHub
- URL: https://github.com/yegor256/tacky
- Owner: yegor256
- License: mit
- Created: 2020-04-26T14:02:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-15T15:39:24.000Z (over 1 year ago)
- Last Synced: 2024-10-16T19:31:01.975Z (over 1 year ago)
- Topics: cache, memoization, ruby-gem
- Language: Ruby
- Homepage: https://rubygems.org/gems/tacky
- Size: 108 KB
- Stars: 12
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/yegor256/tacky)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/tacky/actions/workflows/rake.yml)
[](http://badge.fury.io/rb/tacky)
[](https://codeclimate.com/github/yegor256/tacky/maintainability)
[](http://rubydoc.info/github/yegor256/tacky/master/frames)
[](https://hitsofcode.com/view/github/yegor256/tacky)
[](https://github.com/yegor256/tacky/blob/master/LICENSE.txt)
First, install it:
```bash
$ gem install tacky
```
Then, use it like this:
```ruby
require 'tacky'
obj = Tacky.new(obj)
```
That's it, all method calls will be cached. This means that only the first
call of any method will actually reach your object. All consecutive calls
will be intercepted by the `Tacky` decorator, which will return
previously calculated values. The decorator keeps all values in its internal
`Hash`.
If you want all methods of everything your methods return be cached too, you
need to use "deep" caching (it's `true` by default):
```ruby
obj = Tacky.new(obj, deep: true)
```
Keep in mind that `Tacky` is thread-safe.
## 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/) 2.3+ and
[Bundler](https://bundler.io/) installed. Then:
```
$ bundle update
$ bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.