Sha256: 25b4a64c7ec89ad0637699c29f4467c5df6b251d1cfd1d2d697a3a7adbcaa291

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# Mememaster

Mememaster is a gem for memoization in Ruby. Example:

## Usage

```ruby
class A
  include Mememaster

  memoize def call
    puts "calculating"
    42
  end

  # or:
  # def call
  #   ...
  # end
  # memoize :call
end

a = A.new
a.call # => 42
a.call # => 42
a.call # => 42

# Text will be printed only once.
```

## Difference with other gems
Mememaster is very similar to [Memoist](https://github.com/matthewrudy/memoist). The difference is that it doesn't override methods, instead it uses Ruby 2 `Module.prepend` feature. This approach is cleaner and it allows subclasses' methods to work properly: if you redefine a memoized method in a subclass, it's not memoized by default, but you can memoize it normally (without using awkward `identifier: ` argument) and it will just work.

The other key difference is that it doesn't change method's signature (no extra `reload` param). If you need unmemoized result of method, just create an unmemoized version like this:

```ruby
memoize def users
  get_users
end

def get_users
  # ...
end
```

Alternatively, you can clear the whole instance's cache:

```ruby
a.clear_mememaster_cache!
```

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mememaster-0.3.0 README.md