[英]Ruby gem equivalent of PERL storable
Does Ruby have a gem equivalent of PERL's Storable? Ruby是否具有与PERL的Storable相当的宝石?
I have tried rcstorable, but it only reads, it does not save. 我已经尝试过rcstorable,但是它只能读取,不能保存。
Thanks. 谢谢。
Take a look at PStore, maybe that's what you are looking for. 看一下PStore,也许这就是您想要的。
http://ruby-doc.org/stdlib-2.1.0/libdoc/pstore/rdoc/PStore.html http://ruby-doc.org/stdlib-2.1.0/libdoc/pstore/rdoc/PStore.html
It's in the Stdlib, so no gem is required. 它在Stdlib中,因此不需要gem。
You can do the equivalent of Storable's freeze and thaw using Marshal
: 您可以使用
Marshal
进行Storable的冻结和解冻操作:
In Perl: 在Perl中:
use Storable;
my $serialised_data = freeze( $data_ref );
# and later
my $data_ref = thaw( $serialised_data );
In Ruby: 在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. 一个很大的不同-与Ruby的
Marshal
相比, Storable
“开箱即用”地覆盖更多的Perl库对象,对于Ruby中的非核心对象,有时您可能需要自己添加对Marshal的支持。 All the basic types - numbers, strings, arrays, hashes - work just fine though. 所有基本类型-数字,字符串,数组,哈希-都可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.