https://github.com/dkubb/memoizable
Memoize method return values
https://github.com/dkubb/memoizable
Keywords from Contributors
activejob activerecord mvc code-formatter rubocop static-code-analysis dry-rb ruby-syntax unparser
Last synced: about 2 hours ago
JSON representation
Repository metadata
Memoize method return values
- Host: GitHub
- URL: https://github.com/dkubb/memoizable
- Owner: dkubb
- License: mit
- Created: 2013-09-28T04:46:50.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2026-02-10T11:08:41.000Z (21 days ago)
- Last Synced: 2026-02-15T15:51:41.314Z (16 days ago)
- Language: Ruby
- Size: 182 KB
- Stars: 112
- Watchers: 9
- Forks: 12
- Open Issues: 2
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
README.md
Memoizable
Memoize method return values
Changelog
See CHANGELOG.md for details.
Contributing
See CONTRIBUTING.md for details.
Rationale
Memoization is an optimization that saves the return value of a method so it
doesn't need to be re-computed every time that method is called. For example,
perhaps you've written a method like this:
class Planet
# This is the equation for the area of a sphere. If it's true for a
# particular instance of a planet, then that planet is spherical.
def spherical?
4 * Math::PI * radius ** 2 == area
end
end
This code will re-compute whether a particular planet is spherical every time
the method is called. If the method is called more than once, it may be more
efficient to save the computed value in an instance variable, like so:
class Planet
def spherical?
@spherical ||= 4 * Math::PI * radius ** 2 == area
end
end
One problem with this approach is that, if the return value is false, the
value will still be computed each time the method is called. It also becomes
unweildy for methods that grow to be longer than one line.
These problems can be solved by mixing-in the Memoizable module and memoizing
the method.
require 'memoizable'
class Planet
include Memoizable
def spherical?
4 * Math::PI * radius ** 2 == area
end
memoize :spherical?
end
Warning
The example above assumes that the radius and area of a planet will not change
over time. This seems like a reasonable assumption but such an assumption is
not safe in every domain. If it was possible for one of the attributes to
change between method calls, memoizing that value could produce the wrong
result. Please keep this in mind when considering which methods to memoize.
Supported Ruby Versions
This library aims to support and is tested against the following Ruby versions:
- Ruby 3.2
- Ruby 3.3
- Ruby 3.4
- Ruby 4.0
If something doesn't work on one of these versions, it's a bug.
Copyright
Copyright © 2013-2026 Dan Kubb, Erik Berlin. See LICENSE for details.
Owner metadata
- Name: Dan Kubb
- Login: dkubb
- Email:
- Kind: user
- Description:
- Website:
- Location: Mission, BC, Canada
- Twitter: dkubb
- Company: Betterment
- Icon url: https://avatars.githubusercontent.com/u/133?v=4
- Repositories: 42
- Last ynced at: 2023-04-10T00:16:29.799Z
- Profile URL: https://github.com/dkubb
GitHub Events
Total
- Delete event: 2
- Pull request event: 13
- Fork event: 1
- Issues event: 2
- Watch event: 1
- Issue comment event: 3
- Push event: 20
- Pull request review comment event: 5
- Pull request review event: 5
- Create event: 2
Last Year
- Delete event: 1
- Pull request event: 9
- Issues event: 1
- Push event: 8
- Pull request review event: 2
- Pull request review comment event: 2
- Create event: 2
Committers metadata
Last synced: 1 day ago
Total Commits: 216
Total Committers: 7
Avg Commits per committer: 30.857
Development Distribution Score (DDS): 0.306
Commits in past year: 22
Committers in past year: 1
Avg Commits per committer in past year: 22.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Dan Kubb | d****b@g****m | 150 |
| Erik Michaels-Ober | s****k@g****m | 57 |
| Tim Liner | t****r@g****m | 4 |
| Ray Zane | r****e@g****m | 2 |
| Yannick Schutz | y****z@g****m | 1 |
| Markus Schirp | m****j@s****m | 1 |
| Blake Hyde | b****e@o****m | 1 |
Committer domains:
- on-site.com: 1
- schirp-dso.com: 1
Issue and Pull Request metadata
Last synced: 3 days ago
Total issues: 12
Total pull requests: 22
Average time to close issues: 6 months
Average time to close pull requests: 11 months
Total issue authors: 8
Total pull request authors: 7
Average comments per issue: 6.75
Average comments per pull request: 3.09
Merged pull request: 11
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 1
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: 1
Past year average comments per issue: 0
Past year average comments per pull request: 0.0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- sferik (3)
- BiggerNoise (2)
- solnic (2)
- ianbradbury (1)
- bartoszkopinski (1)
- sg552 (1)
- mfinelli (1)
- mbj (1)
Top Pull Request Authors
- dkubb (9)
- mbj (6)
- rzane (2)
- sferik (2)
- fnordfish (1)
- asthasr (1)
- ys (1)
Top Issue Labels
Top Pull Request Labels
- maintenance (3)
- merge-ready (3)
Package metadata
- Total packages: 13
-
Total downloads:
- rubygems: 115,473,462 total
- Total docker downloads: 1,544,123,008
- Total dependent packages: 29 (may contain duplicates)
- Total dependent repositories: 12,058 (may contain duplicates)
- Total versions: 34
- Total maintainers: 3
gem.coop: memoizable
Memoize method return values
- Homepage: https://github.com/dkubb/memoizable
- Documentation: http://www.rubydoc.info/gems/memoizable/
- Licenses: MIT
- Latest release: 0.5.0 (published 3 days ago)
- Last Synced: 2026-03-01T07:34:12.147Z (3 days ago)
- Versions: 8
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 57,734,556 Total
- Docker Downloads: 772,061,504
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Docker downloads count: 0.121%
- Average: 0.146%
- Downloads: 0.462%
- Maintainers (3)
ubuntu-22.04: ruby-memoizable
- Homepage: https://github.com/dkubb/memoizable
- Licenses: mit
- Latest release: 0.4.2-2 (published 18 days ago)
- Last Synced: 2026-02-13T13:20:19.627Z (18 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.793%
- Stargazers count: 1.406%
- Forks count: 1.767%
rubygems.org: memoizable
Memoize method return values
- Homepage: https://github.com/dkubb/memoizable
- Documentation: http://www.rubydoc.info/gems/memoizable/
- Licenses: MIT
- Latest release: 0.5.0 (published 3 days ago)
- Last Synced: 2026-03-01T20:01:30.083Z (2 days ago)
- Versions: 8
- Dependent Packages: 29
- Dependent Repositories: 12,058
- Downloads: 57,738,906 Total
- Docker Downloads: 772,061,504
-
Rankings:
- Docker downloads count: 0.142%
- Dependent repos count: 0.312%
- Downloads: 0.405%
- Dependent packages count: 0.803%
- Average: 2.599%
- Stargazers count: 5.218%
- Forks count: 8.716%
- Maintainers (3)
proxy.golang.org: github.com/dkubb/memoizable
- Homepage:
- Documentation: https://pkg.go.dev/github.com/dkubb/memoizable#section-documentation
- Licenses: mit
- Latest release: v0.5.0 (published 5 days ago)
- Last Synced: 2026-03-01T20:01:42.012Z (2 days ago)
- Versions: 8
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 4.463%
- Forks count: 6.374%
- Average: 7.804%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
debian-10: ruby-memoizable
- Homepage: https://github.com/dkubb/memoizable
- Documentation: https://packages.debian.org/buster/ruby-memoizable
- Licenses:
- Latest release: 0.4.2-1 (published 20 days ago)
- Last Synced: 2026-02-13T04:22:52.462Z (19 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-11: ruby-memoizable
- Homepage: https://github.com/dkubb/memoizable
- Documentation: https://packages.debian.org/bullseye/ruby-memoizable
- Licenses:
- Latest release: 0.4.2-2 (published 21 days ago)
- Last Synced: 2026-02-13T08:22:04.608Z (19 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-memoizable
- Homepage: https://github.com/dkubb/memoizable
- Documentation: https://packages.debian.org/bookworm/ruby-memoizable
- Licenses:
- Latest release: 0.4.2-3 (published 19 days ago)
- Last Synced: 2026-02-12T23:34:53.817Z (19 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
debian-13: ruby-memoizable
- Homepage: https://github.com/dkubb/memoizable
- Documentation: https://packages.debian.org/trixie/ruby-memoizable
- Licenses:
- Latest release: 0.4.2-3 (published 19 days ago)
- Last Synced: 2026-02-13T13:17:26.193Z (18 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
Dependencies
- rspec ~> 3.1.0 development
- simplecov ~> 0.9.1 development
- rake ~> 10.1
- thread_safe ~> 0.3, >= 0.3.4
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
Score: 27.91195666207827