{"id":15685431,"url":"https://github.com/hparker/ruby_memoize_method","last_synced_at":"2025-03-30T11:12:09.287Z","repository":{"id":56883252,"uuid":"45873156","full_name":"HParker/ruby_memoize_method","owner":"HParker","description":"5 character method memoization in ruby.","archived":false,"fork":false,"pushed_at":"2015-12-04T06:42:45.000Z","size":6,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T07:19:21.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HParker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-09T23:12:43.000Z","updated_at":"2015-12-07T06:28:43.000Z","dependencies_parsed_at":"2022-08-20T13:10:44.620Z","dependency_job_id":null,"html_url":"https://github.com/HParker/ruby_memoize_method","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HParker%2Fruby_memoize_method","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HParker%2Fruby_memoize_method/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HParker%2Fruby_memoize_method/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HParker%2Fruby_memoize_method/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HParker","download_url":"https://codeload.github.com/HParker/ruby_memoize_method/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246308051,"owners_count":20756482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T17:25:13.369Z","updated_at":"2025-03-30T11:12:09.269Z","avatar_url":"https://github.com/HParker.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MemoizeMethod\n\nMemoize Method lets you memoize the return value of methods methods with a single word.\n\n```ruby\ncache def my_expensive_computation\n  ...\nend\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'memoize_method'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install memoize_method\n\n## Usage\n\nYou are going to want to extend MemoizeMethod in your class\n\n```ruby\nclass A\n  extend MemoizeMethod\nend\n\nirb\u003e A.methods - Object.methods\n=\u003e [:cache]\n```\n\nNow lets cache our method.\n\n```ruby\nclass A\n  extend MemoizeMethod\n  cache def foo\n    Time.now\n  end\nend\n\nirb\u003e A.new.methods - Object.new.methods\n=\u003e [:foo, :cacheless_foo, :recompute_foo]\n```\n\nNow you have 3 methods where you defined `foo`,\n- `foo` is will compute the first time, then cache after that.\n- `cacheless_foo` lets you get at the current value without busting the cache.\n- `recompute_foo` will bust the cache and assign it to the new value.\n\nExample:\n```ruby\nirb\u003e a = A.new\n=\u003e #\u003cA:0x007f98212599f8\u003e\nirb\u003e a.foo\n=\u003e 2015-11-15 10:38:09 -0800\nirb\u003e a.foo\n=\u003e 2015-11-15 10:38:09 -0800\nirb\u003e a.foo == a.foo\n=\u003e true\nirb\u003e a.cacheless_foo\n=\u003e 2015-11-15 10:38:41 -0800\nirb\u003e a.cacheless_foo != a.foo\n=\u003e true\nirb(main):018:0\u003e a.recompute_foo\n=\u003e 2015-11-15 10:41:01 -0800\nirb(main):019:0\u003e a.foo\n=\u003e 2015-11-15 10:41:01 -0800\nirb(main):020:0\u003e a.recompute_foo == a.foo\n=\u003e true\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/hparker/memoize_method.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhparker%2Fruby_memoize_method","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhparker%2Fruby_memoize_method","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhparker%2Fruby_memoize_method/lists"}