class Tins::LRUCache
Attributes
Public Class Methods
Source
# File lib/tins/lru_cache.rb, line 15 def initialize(capacity) @capacity = capacity @data = {} end
Public Instance Methods
Source
# File lib/tins/lru_cache.rb, line 22 def [](key) case value = @data.delete(key){ not_exist } when not_exist nil else @data[key] = value end end
Source
# File lib/tins/lru_cache.rb, line 31 def []=(key, value) @data.delete(key) @data[key] = value if @data.size > @capacity @data.delete(@data.keys.first) end value end
Source
# File lib/tins/lru_cache.rb, line 40 def each(&block) @data.reverse_each(&block) end
Private Instance Methods
Source
# File lib/tins/lru_cache.rb, line 58 def not_exist self.class.send(:not_exist) end