Skip to content

Instantly share code, notes, and snippets.

@prehnRA
Created October 9, 2015 18:28
Show Gist options
  • Save prehnRA/8f578e073326a62d9e17 to your computer and use it in GitHub Desktop.
Save prehnRA/8f578e073326a62d9e17 to your computer and use it in GitHub Desktop.
class LRS
SIZE = 10
attr_accessor :key_history, :inner
def initialize()
self.key_history = []
self.inner = {}
end
def get(key)
inner[key]
end
def set(key, value)
inner[key] = value
# If we have the key already, move it up
if i = key_history.find_index(key)
key_history.delete_at(i)
end
key_history << key
if key_history.length > SIZE
inner.delete(key_history[0])
key_history.delete_at(0)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment