class LRU::Cache

Constants

VERSION

Attributes

content[R]
max[R]

Public Class Methods

new(max, hash={}) click to toggle source
# File lib/lru/cache.rb, line 14
def initialize(max, hash={})
  @max = max
  @content = hash
end

Public Instance Methods

[](key) click to toggle source
# File lib/lru/cache.rb, line 19
def [](key)
  content[key] = content.delete(key) if content.has_key? key
end
Also aliased as: get
[]=(key, value) click to toggle source
# File lib/lru/cache.rb, line 24
def []=(key, value)
  content.delete key if content.has_key? key
  content.delete(content.first.first) if content.length == max
  content[key] = value
end
Also aliased as: set
get(key)
Alias for: []
set(key, value)
Alias for: []=