class Psych::DBM
YAML + DBM = YDBM
YAML::DBM provides the same interface as ::DBM.
However, while DBM only allows strings for both keys and values, this library allows one to use most Ruby objects for values by first converting them to YAML. Keys must be strings.
Conversion to and from YAML is performed automatically.
See the documentation for ::DBM and ::YAML for more information.
Constants
- VERSION
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 29
def []: (String key) -> untyped
Return value associated with key from database.
Returns nil if there is no such key.
See fetch for more information.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 41
def []=: (String key, untyped val) -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 94
def delete: (String key) -> untyped
Deletes value from database associated with key.
Returns value or nil.
() { (untyped, untyped) → untyped } → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 105
def delete_if: () { (untyped, untyped) -> untyped } -> untyped
Calls the given block once for each key, value pair in the database. Deletes all entries for which the block returns true.
Returns self.
() { (untyped, untyped) → untyped } → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 124
def each_pair: () { (untyped, untyped) -> untyped } -> untyped
Calls the given block once for each key, value pair in the database.
Returns self.
() { (untyped) → untyped } → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 134
def each_value: () { (untyped) -> untyped } -> untyped
Calls the given block for each value in database.
Returns self.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 56
def fetch: (String keystr, ?untyped? ifnone) { (untyped) -> untyped } -> untyped
Return value associated with key.
If there is no value for key and no block is given, returns ifnone.
Otherwise, calls block passing in the given key.
See ::DBM#fetch for more information.
(untyped val) → (::TrueClass | ::FalseClass)
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 150
def has_value?: (untyped val) -> (::TrueClass | ::FalseClass)
Returns true if specified value is found in the database.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 68
def index: (String keystr) -> untyped
Deprecated, used YAML::DBM#key instead.
Note: YAML::DBM#index makes warning from internal of ::DBM#index. It says ‘DBM#index is deprecated; use DBM#key’, but DBM#key behaves not same as DBM#index.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 162
def invert: () -> Hash[untyped, untyped]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 76
def key: (String keystr) -> String
Returns the key for the specified value.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 114
def reject: () { (untyped, untyped) -> untyped } -> Hash[untyped, untyped]
Converts the contents of the database to an in-memory Hash, then calls Hash#reject with the specified code block, returning a new Hash.
(Hash[untyped, untyped] | DBM hsh) → Psych::DBM
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 172
def replace: (Hash[untyped, untyped] | DBM hsh) -> Psych::DBM
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 195
def select: (*untyped keys) { (untyped, untyped) -> untyped } -> Array[untyped]
If a block is provided, returns a new array containing [key, value] pairs for which the block returns true.
Otherwise, same as values_at
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 183
def shift: () -> (Array[untyped] | untyped)
Removes a [key, value] pair from the database, and returns it. If the database is empty, returns nil.
The order in which values are removed/returned is not guaranteed.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 206
def store: (String key, untyped val) -> untyped
Stores value in database with key as the index. value is converted to YAML before being stored.
Returns value
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 226
def to_a: () -> Array[untyped]
Converts the contents of the database to an array of [key, value] arrays, and returns it.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 235
def to_hash: () -> Hash[untyped, untyped]
Converts the contents of the database to an in-memory Hash object, and returns it.
(Hash[untyped, untyped]) → Psych::DBM
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 217
def update: (Hash[untyped, untyped]) -> Psych::DBM
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/psych/0/dbm.rbs, line 142
def values: () -> untyped
Returns an array of values from the database.