End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
PStore#fetch
fetch(key, default=PStore::Error)
lib/pstore.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/pstore.rb, line 436
def fetch(key, default=PStore::Error)
in_transaction
unless @table.key? key
if default == PStore::Error
raise PStore::Error, format("undefined key `%s'", key)
else
return default
end
end
@table[key]
end
Like [], except that it accepts a default value for the store. If the key does not exist:
-
Raises an exception if
defaultisPStore::Error. -
Returns the value of
defaultotherwise:Exampleexample_store do |store| store.transaction do store.fetch(:nope, nil) # => nil store.fetch(:nope) # Raises an exception. end end
Raises an exception if called outside a transaction block.
See also
#empty_marshal_data
#in_transaction
#empty_marshal_checksum
#in_transaction_wr
also in
3.4 · 3.3 · 3.1 · 3.0