Does Ruby have a gem equivalent of PERL's Storable?
I have tried rcstorable, but it only reads, it does not save.
Thanks.
Ruby gem equivalent of PERL storable
231 views Asked by user1134991 At
2
There are 2 answers
0
On
You can do the equivalent of Storable's freeze and thaw using Marshal
:
In Perl:
use Storable;
my $serialised_data = freeze( $data_ref );
# and later
my $data_ref = thaw( $serialised_data );
In Ruby:
serialised_data = Marshal.dump( object );
# and later
object = Marshal.load( serialised_data );
One big difference - Storable
covers more Perl library objects "out of the box" than Ruby's Marshal
does, for non-core objects in Ruby sometimes you may need to add support for Marshal yourself. All the basic types - numbers, strings, arrays, hashes - work just fine though.
Take a look at PStore, maybe that's what you are looking for.
http://ruby-doc.org/stdlib-2.1.0/libdoc/pstore/rdoc/PStore.html
It's in the Stdlib, so no gem is required.