/usr/lib/ruby/1.8/yaml/dbm.rb is in libruby1.8 1.8.7.352-2ubuntu1.6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | require 'yaml'
require 'dbm'
#
# YAML + DBM = YDBM
# - Same interface as DBM class
#
module YAML
class DBM < ::DBM
VERSION = "0.1"
def []( key )
fetch( key )
end
def []=( key, val )
store( key, val )
end
def fetch( keystr, ifnone = nil )
begin
val = super( keystr )
return YAML::load( val ) if String === val
rescue IndexError
end
if block_given?
yield keystr
else
ifnone
end
end
def index( keystr )
super( keystr.to_yaml )
end
def values_at( *keys )
keys.collect { |k| fetch( k ) }
end
def delete( key )
v = super( key )
if String === v
v = YAML::load( v )
end
v
end
def delete_if
del_keys = keys.dup
del_keys.delete_if { |k| yield( k, fetch( k ) ) == false }
del_keys.each { |k| delete( k ) }
self
end
def reject
hsh = self.to_hash
hsh.reject { |k,v| yield k, v }
end
def each_pair
keys.each { |k| yield k, fetch( k ) }
self
end
def each_value
super { |v| yield YAML::load( v ) }
self
end
def values
super.collect { |v| YAML::load( v ) }
end
def has_value?( val )
each_value { |v| return true if v == val }
return false
end
def invert
h = {}
keys.each { |k| h[ self.fetch( k ) ] = k }
h
end
def replace( hsh )
clear
update( hsh )
end
def shift
a = super
a[1] = YAML::load( a[1] ) if a
a
end
def select( *keys )
if block_given?
self.keys.collect { |k| v = self[k]; [k, v] if yield k, v }.compact
else
values_at( *keys )
end
end
def store( key, val )
super( key, val.to_yaml )
val
end
def update( hsh )
hsh.keys.each do |k|
self.store( k, hsh.fetch( k ) )
end
self
end
def to_a
a = []
keys.each { |k| a.push [ k, self.fetch( k ) ] }
a
end
def to_hash
h = {}
keys.each { |k| h[ k ] = self.fetch( k ) }
h
end
alias :each :each_pair
end
end
|