105
105
# end
106
106
#
107
107
# Instance methods in \PStore may be called only from within a transaction
108
- # () exception: #path may be called from anywhere).
108
+ # (exception: #path may be called from anywhere).
109
109
# This assures that the call is executed only when the store is secure and stable.
110
110
#
111
111
# As seen above, changes in a transaction are made automatically
@@ -367,9 +367,6 @@ def in_transaction_wr
367
367
end
368
368
private :in_transaction , :in_transaction_wr
369
369
370
- # :call-seq:
371
- # pstore[key]
372
- #
373
370
# Returns the object for the given +key+ if the key exists.
374
371
# +nil+ otherwise;
375
372
# if not +nil+, the returned value is an object or a hierarchy of objects:
@@ -384,14 +381,11 @@ def in_transaction_wr
384
381
# See also {Deep Root Values}[rdoc-ref:PStore@Deep+Root+Values].
385
382
#
386
383
# Raises an exception if called outside a transaction block.
387
- def []( name )
384
+ def []( key )
388
385
in_transaction
389
- @table [ name ]
386
+ @table [ key ]
390
387
end
391
388
392
- # :call-seq:
393
- # fetch(key)
394
- #
395
389
# Like #[], except that it accepts a default value for the store.
396
390
# If the root for the given +key+ does not exist:
397
391
#
@@ -404,21 +398,18 @@ def [](name)
404
398
# end
405
399
#
406
400
# Raises an exception if called outside a transaction block.
407
- def fetch ( name , default = PStore ::Error )
401
+ def fetch ( key , default = PStore ::Error )
408
402
in_transaction
409
- unless @table . key? name
403
+ unless @table . key? key
410
404
if default == PStore ::Error
411
- raise PStore ::Error , format ( "undefined root name `%s'" , name )
405
+ raise PStore ::Error , format ( "undefined root key `%s'" , key )
412
406
else
413
407
return default
414
408
end
415
409
end
416
- @table [ name ]
410
+ @table [ key ]
417
411
end
418
412
419
- # :call-seq:
420
- # pstore[key] = value
421
- #
422
413
# Creates or replaces an object or hierarchy of objects
423
414
# at the root for +key+:
424
415
#
@@ -430,14 +421,11 @@ def fetch(name, default=PStore::Error)
430
421
# See also {Deep Root Values}[rdoc-ref:PStore@Deep+Root+Values].
431
422
#
432
423
# Raises an exception if called outside a transaction block.
433
- def []=( name , value )
424
+ def []=( key , value )
434
425
in_transaction_wr
435
- @table [ name ] = value
426
+ @table [ key ] = value
436
427
end
437
428
438
- # :call-seq:
439
- # delete(key)
440
- #
441
429
# Removes and returns the value at +key+ if it exists:
442
430
#
443
431
# store = PStore.new('t.store')
@@ -449,9 +437,9 @@ def []=(name, value)
449
437
# Returns +nil+ if there is no such root.
450
438
#
451
439
# Raises an exception if called outside a transaction block.
452
- def delete ( name )
440
+ def delete ( key )
453
441
in_transaction_wr
454
- @table . delete name
442
+ @table . delete key
455
443
end
456
444
457
445
# Returns an array of the keys of the existing roots:
@@ -466,19 +454,16 @@ def roots
466
454
@table . keys
467
455
end
468
456
469
- # :call-seq:
470
- # root?(key)
471
- #
472
457
# Returns +true+ if there is a root for +key+, +false+ otherwise:
473
458
#
474
459
# store.transaction do
475
460
# store.root?(:foo) # => true
476
461
# end
477
462
#
478
463
# Raises an exception if called outside a transaction block.
479
- def root? ( name )
464
+ def root? ( key )
480
465
in_transaction
481
- @table . key? name
466
+ @table . key? key
482
467
end
483
468
484
469
# Returns the string file path used to create the store:
0 commit comments