module CachedAttr

This module implements attributes whose reader method executes once, and the returned value is cached for later use. This might be handy for expensive operations.

An example, given the following method:

def object_to_get

if @object_to_get.nil?
  @object_to_get = [code_to_retrieve_object]
end
@object_to_get

end

…the cached attribute format would be:

cache_attr :object_to_get do

[code_to_retrieve_object]

end

Public Class Methods

included(base) click to toggle source
# File lib/cached_attr.rb, line 20
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

cached_attributes_store() click to toggle source

The store of cached properties

# File lib/cached_attr.rb, line 111
def cached_attributes_store
  @cached_attributes_store ||= {}
end