In Files

  • yaml/dbm.rb

Class/Module Index [+]

Quicksearch

YAML::DBM

Constants

VERSION

Public Instance Methods

[]( key ) click to toggle source
 
               # File yaml/dbm.rb, line 11
def []( key )
    fetch( key )
end
            
[]=( key, val ) click to toggle source
 
               # File yaml/dbm.rb, line 14
def []=( key, val )
    store( key, val )
end
            
delete( key ) click to toggle source
 
               # File yaml/dbm.rb, line 35
def delete( key )
    v = super( key )
    if String === v
        v = YAML.load( v )
    end
    v
end
            
delete_if() click to toggle source
 
               # File yaml/dbm.rb, line 42
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
            
each() click to toggle source
Alias for: each_pair
each_pair() click to toggle source
 
               # File yaml/dbm.rb, line 52
def each_pair
    keys.each { |k| yield k, fetch( k ) }
    self
end
            
Also aliased as: each
each_value() click to toggle source
 
               # File yaml/dbm.rb, line 56
def each_value
    super { |v| yield YAML.load( v ) }
    self
end
            
fetch( keystr, ifnone = nil ) click to toggle source
 
               # File yaml/dbm.rb, line 17
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
            
has_value?( val ) click to toggle source
 
               # File yaml/dbm.rb, line 63
def has_value?( val )
    each_value { |v| return true if v == val }
    return false
end
            
index( keystr ) click to toggle source
 
               # File yaml/dbm.rb, line 29
def index( keystr )
    super( keystr.to_yaml )
end
            
invert() click to toggle source
 
               # File yaml/dbm.rb, line 67
def invert
    h = {}
    keys.each { |k| h[ self.fetch( k ) ] = k }
    h
end
            
reject() click to toggle source
 
               # File yaml/dbm.rb, line 48
def reject
    hsh = self.to_hash
    hsh.reject { |k,v| yield k, v }
end
            
replace( hsh ) click to toggle source
 
               # File yaml/dbm.rb, line 72
def replace( hsh )
    clear
    update( hsh )
end
            
select( *keys ) click to toggle source
 
               # File yaml/dbm.rb, line 81
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
            
shift() click to toggle source
 
               # File yaml/dbm.rb, line 76
def shift
    a = super
    a[1] = YAML.load( a[1] ) if a
    a
end
            
store( key, val ) click to toggle source
 
               # File yaml/dbm.rb, line 88
def store( key, val )
    super( key, val.to_yaml )
    val
end
            
to_a() click to toggle source
 
               # File yaml/dbm.rb, line 98
def to_a
    a = []
    keys.each { |k| a.push [ k, self.fetch( k ) ] }
    a
end
            
to_hash() click to toggle source
 
               # File yaml/dbm.rb, line 103
def to_hash
    h = {}
    keys.each { |k| h[ k ] = self.fetch( k ) }
    h
end
            
update( hsh ) click to toggle source
 
               # File yaml/dbm.rb, line 92
def update( hsh )
    hsh.keys.each do |k|
        self.store( k, hsh.fetch( k ) )
    end
    self
end
            
values() click to toggle source
 
               # File yaml/dbm.rb, line 60
def values
    super.collect { |v| YAML.load( v ) }
end
            
values_at( *keys ) click to toggle source
 
               # File yaml/dbm.rb, line 32
def values_at( *keys )
    keys.collect { |k| fetch( k ) }
end