Sha256: 6444086d69531fa6acc9e4e1961c76c1115cb599edf474680f073d087f047c99
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# Mem [![CI](https://github.com/r7kamura/mem/actions/workflows/ci.yml/badge.svg)](https://github.com/r7kamura/mem/actions/workflows/ci.yml) Memoize method calls. ## Installation Install the gem and add to the application's Gemfile by executing: ``` bundle add mem ``` If bundler is not being used to manage dependencies, install the gem by executing: ``` gem install mem ``` ## Usage ```ruby class Foo include Mem def initialize @count = 0 end def bar baz end # `memoize` defines bar_with_memoize & bar_without_memoize, # and the result of the 1st method call is stored into @memoized_table. memoize :bar private def baz @count += 1 end end foo = Foo.new foo.bar #=> 1 foo.bar #=> 1 foo.bar #=> 1 foo.has_memoized?(:bar) #=> true foo.memoized(:bar) #=> 1 foo.memoized_table #=> { bar: 1 } ``` ### core ext You can `require "mem/core_ext"` to skip `include Mem`, while this extends Object class. ```ruby require "mem/core_ext" class A def x puts 1 end memoize :x end a = A.new a.x #=> 1 a.x #=> nothing logged out a.x #=> nothing logged out ```
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mem-0.2.0 | README.md |