https://github.com/matthewrudy/memoist
ActiveSupport::Memoizable with a few enhancements
https://github.com/matthewrudy/memoist
Keywords from Contributors
activejob activerecord mvc rubygems rspec static-code-analysis code-formatter rubocop rack omniauth
Last synced: about 23 hours ago
JSON representation
Repository metadata
ActiveSupport::Memoizable with a few enhancements
- Host: GitHub
- URL: https://github.com/matthewrudy/memoist
- Owner: matthewrudy
- License: mit
- Created: 2011-12-07T04:20:35.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-04-30T18:32:03.000Z (almost 2 years ago)
- Last Synced: 2026-01-04T07:56:54.323Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 106 KB
- Stars: 925
- Watchers: 20
- Forks: 99
- Open Issues: 28
- Releases: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
README.md
Memoist
Memoist is an extraction of ActiveSupport::Memoizable.
Since June 2011 ActiveSupport::Memoizable has been deprecated.
But I love it,
and so I plan to keep it alive.
Usage
Just extend with the Memoist module
require 'memoist'
class Person
extend Memoist
def social_security
puts "execute!"
decrypt_social_security
end
memoize :social_security
end
person = Person.new
person.social_security
# execute!
# => (returns decrypt_social_security)
person.social_security
# => (returns the memoized value)
And person.social_security will only be calculated once.
Every memoized function (which initially was not accepting any arguments) has a (reload)
argument you can pass in to bypass and reset the memoization:
def some_method
Time.now
end
memoize :some_method
Calling some_method will be memoized, but calling some_method(true) will rememoize each time.
You can even memoize method that takes arguments.
class Person
def taxes_due(income)
income * 0.40
end
memoize :taxes_due
end
This will only be calculated once per value of income.
You can also memoize class methods.
class Person
class << self
extend Memoist
def with_overdue_taxes
# ...
end
memoize :with_overdue_taxes
end
end
When a sub-class overrides one of its parent's methods and you need to memoize both.
Then you can use the :identifier parameter in order to help Memoist distinguish between the two.
class Clock
extend Memoist
def now
"The time now is #{Time.now.hour} o'clock and #{Time.now.min} minutes"
end
memoize :now
end
class AccurateClock < Clock
extend Memoist
def now
"#{super} and #{Time.now.sec} seconds"
end
memoize :now, :identifier => :accurate_clock
end
Reload
Each memoized function comes with a way to flush the existing value.
person.social_security # returns the memoized value
person.social_security(true) # bypasses the memoized value and rememoizes it
This also works with a memoized method with arguments
person.taxes_due(100_000) # returns the memoized value
person.taxes_due(100_000, true) # bypasses the memoized value and rememoizes it
If you want to flush the entire memoization cache for an object
person.flush_cache # returns an array of flushed memoized methods, e.g. ["social_security", "some_method"]
Authors
Everyone who contributed to it in the rails repository.
- Joshua Peek
- Tarmo Tänav
- Jeremy Kemper
- Eugene Pimenov
- Xavier Noria
- Niels Ganser
- Carl Lerche & Yehuda Katz
- jeem
- Jay Pignata
- Damien Mathieu
- José Valim
- Matthew Rudy Jacobs
Contributing
- Fork it ( https://github.com/matthewrudy/memoist/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 new Pull Request
License
Released under the MIT License, just as Ruby on Rails is.
Owner metadata
- Name: Matthew Rudy Jacobs
- Login: matthewrudy
- Email:
- Kind: user
- Description: Technical Architect @ministryofjustice, former Architect @GoGoVan, Organiser of @hkcodeconf and @codeaholicshk. Mandarin (and semi-Cantonese) speaker
- Website: https://matthewrudy.com
- Location: London / Hong Kong
- Twitter:
- Company: GoGoVan
- Icon url: https://avatars.githubusercontent.com/u/8659?v=4
- Repositories: 160
- Last ynced at: 2023-04-09T04:55:30.119Z
- Profile URL: https://github.com/matthewrudy
GitHub Events
Total
- Fork event: 1
- Watch event: 9
- Issue comment event: 1
Last Year
- Fork event: 1
- Watch event: 2
- Issue comment event: 1
Committers metadata
Last synced: 8 days ago
Total Commits: 105
Total Committers: 20
Avg Commits per committer: 5.25
Development Distribution Score (DDS): 0.419
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Matthew Rudy Jacobs | M****s@g****m | 61 |
| Joe Rafaniello | j****e@r****m | 12 |
| Seb Jacobs | me@s****m | 9 |
| Peter Boling | p****g@g****m | 3 |
| Zach Hale | z****e@g****m | 3 |
| Igor Zubkov | i****v@g****m | 2 |
| Joshua Pinter | j****r@g****m | 2 |
| Brady Love and Johnneylee Jack Rollins | b****y@a****t | 1 |
| Gregory Perry | g****g@d****m | 1 |
| kota.nomura | k****a@a****p | 1 |
| Andrey Chernih | a****h@g****m | 1 |
| Brandon Zylstra | b****a@g****m | 1 |
| Faraz Yashar | f****r@g****m | 1 |
| Jean Boussier | j****r@g****m | 1 |
| Joe Burns | j****s@g****m | 1 |
| Matias Korhonen | k****t@g****m | 1 |
| Olivier Lacan | hi@o****m | 1 |
| PikachuEXE | p****e@g****m | 1 |
| Yusuke Nakamura | y****5@g****m | 1 |
| fervic | r****o@r****m | 1 |
Committer domains:
- runawaybit.com: 1
- olivierlacan.com: 1
- aktsk.jp: 1
- dapperbot.com: 1
- artemis.net: 1
- sebjacobs.com: 1
- redhat.com: 1
Issue and Pull Request metadata
Last synced: 3 months ago
Total issues: 43
Total pull requests: 54
Average time to close issues: 3 months
Average time to close pull requests: 19 days
Total issue authors: 38
Total pull request authors: 36
Average comments per issue: 4.05
Average comments per pull request: 2.04
Merged pull request: 30
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- JacobEvelyn (5)
- findchris (2)
- vemv (1)
- JelF (1)
- patbl (1)
- omgitsbillryan (1)
- onyxblade (1)
- mikebaldry (1)
- SamGerber-zz (1)
- fny (1)
- ansarada-dantan (1)
- someperfectname (1)
- kenglishhi (1)
- nagyt234 (1)
- ASnow (1)
Top Pull Request Authors
- matthewrudy (8)
- JelF (4)
- jrafanie (4)
- joshuapinter (2)
- olivierlacan (2)
- dark-panda (2)
- edtaupier (2)
- unasuke (2)
- 3nan3 (1)
- onyxblade (1)
- fny (1)
- JoeMcB (1)
- andreychernih (1)
- stevendaniels (1)
- pboling (1)
Top Issue Labels
Top Pull Request Labels
- breaks tests (1)
Package metadata
- Total packages: 13
-
Total downloads:
- rubygems: 613,936,930 total
- Total docker downloads: 1,162,376,186
- Total dependent packages: 187 (may contain duplicates)
- Total dependent repositories: 35,257 (may contain duplicates)
- Total versions: 51
- Total maintainers: 2
gem.coop: memoist
memoize methods invocation
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: http://www.rubydoc.info/gems/memoist/
- Licenses: MIT
- Latest release: 0.16.2 (published over 6 years ago)
- Last Synced: 2026-03-07T22:31:16.612Z (3 days ago)
- Versions: 15
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 306,972,578 Total
- Docker Downloads: 581,188,093
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.059%
- Downloads: 0.079%
- Docker downloads count: 0.159%
- Maintainers (2)
ubuntu-22.04: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Licenses: mit
- Latest release: 0.16.2-2 (published 25 days ago)
- Last Synced: 2026-02-13T13:20:19.053Z (25 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.305%
- Stargazers count: 0.548%
- Forks count: 0.671%
rubygems.org: memoist
memoize methods invocation
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: http://www.rubydoc.info/gems/memoist/
- Licenses: MIT
- Latest release: 0.16.2 (published over 6 years ago)
- Last Synced: 2026-03-07T13:30:33.067Z (3 days ago)
- Versions: 15
- Dependent Packages: 187
- Dependent Repositories: 35,257
- Downloads: 306,964,352 Total
- Docker Downloads: 581,188,093
-
Rankings:
- Downloads: 0.065%
- Dependent repos count: 0.176%
- Dependent packages count: 0.2%
- Docker downloads count: 0.222%
- Average: 0.878%
- Stargazers count: 1.964%
- Forks count: 2.642%
- Maintainers (2)
proxy.golang.org: github.com/matthewrudy/memoist
- Homepage:
- Documentation: https://pkg.go.dev/github.com/matthewrudy/memoist#section-documentation
- Licenses: mit
- Latest release: v0.16.2 (published over 6 years ago)
- Last Synced: 2026-03-06T16:00:37.159Z (4 days ago)
- Versions: 11
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 2.102%
- Forks count: 2.574%
- Average: 6.263%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
debian-11: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: https://packages.debian.org/bullseye/ruby-memoist
- Licenses:
- Latest release: 0.16.2-2 (published 28 days ago)
- Last Synced: 2026-02-13T08:22:04.315Z (25 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-20.04: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Licenses:
- Latest release: 0.16.2-2 (published 25 days ago)
- Last Synced: 2026-02-13T07:17:32.602Z (25 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-23.10: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Licenses:
- Latest release: 0.16.2-3 (published 25 days ago)
- Last Synced: 2026-02-13T18:25:25.753Z (25 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-10: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: https://packages.debian.org/buster/ruby-memoist
- Licenses:
- Latest release: 0.16.0-2 (published 27 days ago)
- Last Synced: 2026-02-13T04:22:52.203Z (26 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-23.04: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Licenses:
- Latest release: 0.16.2-3 (published 27 days ago)
- Last Synced: 2026-02-11T06:43:10.234Z (27 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-12: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: https://packages.debian.org/bookworm/ruby-memoist
- Licenses:
- Latest release: 0.16.2-3 (published 26 days ago)
- Last Synced: 2026-02-12T23:34:53.439Z (26 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
debian-13: ruby-memoist
- Homepage: https://github.com/matthewrudy/memoist
- Documentation: https://packages.debian.org/trixie/ruby-memoist
- Licenses:
- Latest release: 0.16.2-3 (published 26 days ago)
- Last Synced: 2026-02-13T13:17:25.948Z (25 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
Dependencies
- benchmark-ips >= 0 development
- bundler >= 0 development
- minitest ~> 5.10 development
- rake >= 0 development
- rake ~> 10.4 development
- actions/checkout v2 composite
Score: 31.153173964708927