Sha256: 423db557982f748e74af93a391629608c42639faa4e44e961834b0613fa06970

Contents?: true

Size: 311 Bytes

Versions: 3

Compression:

Stored size: 311 Bytes

Contents

module Ro
  class Cache < ::Hash
    def write(key, value)
      self[key] = value
    end

    def read(key, &block)
      if has_key?(key)
        self[key]
      else
        if block
          value = block.call
          write(key, value)
        else
          nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ro-1.1.1 lib/ro/cache.rb
ro-1.1.0 lib/ro/cache.rb
ro-1.0.0 lib/ro/cache.rb