lib/rufus/lru.rb in rufus-lru-1.0 vs lib/rufus/lru.rb in rufus-lru-1.0.1

- old
+ new

@@ -1,8 +1,8 @@ # #-- -# Copyright (c) 2008, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2007-2008, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -34,18 +34,37 @@ # # A Hash that has a max size. After the maxsize has been reached, the # least recently used entries (LRU hence), will be discared to make # room for the new entries. # +# require 'rubygems' +# require 'rufus/lru' +# +# h = LruHash.new 3 +# +# 5.times { |i| h[i] = "a" * i } +# +# puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"} +# +# h[:newer] = "b" +# +# puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"} +# +# class LruHash < Hash + #-- #include MonitorMixin # # seems not necessary for now, and it collides with expool's # @monitors own sync + #++ attr_reader :maxsize + # + # Initializes a LruHash with a given maxsize. + # def initialize (maxsize) super() @maxsize = maxsize