0.0
No release in over 3 years
Easily memoize any operation with this global method that takes a block.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

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.