Skip to content

truecoach/memoize_block

Repository files navigation

Build Status

MemoizeBlock

A simple utility for memoizing.

Usage

  1. Include the MemoizeBlock module early enough in your application's load sequence that it is available when you need it. In Rails, this could be in an initializer.
include MemoizeBlock
  1. Profit!
# basic usage
# creates an @_sum instance variable
def sum
  memoize { Fee.all.pluck(:amount).sum }
end

# override ivar
# creates an @_custom_sum instance variable
def sum
  memoize('custom_sum') { Fee.all.pluck(:amount).sum }
end

Local Development

$ bundle install
$ bundle exec rspec spec

Contributions

Contributions welcomed! Please link an issue in every pull request, and please include tests.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •