Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

PStore#fetch

fetch(key, default=PStore::Error)

Like [], except that it accepts a default value for the store. If the key does not exist:

  • Raises an exception if default is PStore::Error.

  • Returns the value of default otherwise:

    Example
    example_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.