Class: Cubbyhole::SDBM
- Inherits:
-
Object
- Object
- Cubbyhole::SDBM
- Extended by:
- Forwardable
- Defined in:
- lib/cubbyhole/sdbm.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(name) ⇒ SDBM
constructor
A new instance of SDBM.
- #keys ⇒ Object
- #munge_key(key) ⇒ Object
Constructor Details
#initialize(name) ⇒ SDBM
Returns a new instance of SDBM.
8 9 10 11 |
# File 'lib/cubbyhole/sdbm.rb', line 8 def initialize(name) @name = name @sdbm = ::SDBM.new("cubbyhole.sdbm") end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 16 17 |
# File 'lib/cubbyhole/sdbm.rb', line 13 def [](key) if str = @sdbm[munge_key(key)] Marshal.load(str) end end |
#[]=(key, val) ⇒ Object
19 20 21 |
# File 'lib/cubbyhole/sdbm.rb', line 19 def []=(key, val) @sdbm[munge_key(key)] = Marshal.dump(val) end |
#delete(key) ⇒ Object
29 30 31 |
# File 'lib/cubbyhole/sdbm.rb', line 29 def delete(key) @sdbm.delete(munge_key(key)) end |
#keys ⇒ Object
23 24 25 26 27 |
# File 'lib/cubbyhole/sdbm.rb', line 23 def keys @sdbm.keys.grep(/^#{@name}:/).map do |key| key.sub(/^#{@name}:/, "") end end |
#munge_key(key) ⇒ Object
33 34 35 |
# File 'lib/cubbyhole/sdbm.rb', line 33 def munge_key(key) "#{@name}:#{key}" end |