Sha256: 79327a45f0eefd2155e0b00e836a241d181c1275f22ec59eb62aa99d2949e0e0

Contents?: true

Size: 796 Bytes

Versions: 3

Compression:

Stored size: 796 Bytes

Contents

# Mem
Memoize any method call.

## Installation
```
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

3 entries across 3 versions & 1 rubygems

Version Path
mem-0.1.5 README.md
mem-0.1.4 README.md
mem-0.1.3 README.md