bd7lx 发表于 2013-2-4 21:33:38

PStore Meets YAML

http://blog.grayproductions.net/articles/2006/07/30/pstore-meets-yaml

看了这片短文有点惊讶

Pstore应该是

将Ruby对象存入外部文件------比如磁盘文件时使用的类。该类内部使用了Marshal。

Java和PHP类似的做法叫序列化

http://rubycn.ce-lab.net/man/addlib/PStore.html

db = PStore.new("/tmp/foo")db.transaction dop db.rootsary = db["root"] = ary = enddb.transaction dop db["root"]end

必须在transaction块内部访问数据库。其接口类似于Hash。

另外的例子
对象“H”实例化后存储在“/tmp/rb”中,之后便可以直接打开读取该实例的属性和操作该实例方法。


http://www.cnzxh.net/blog/Index.php?month=2005-12&catalogId=0&key=

#!/usr/bin/env rubyrequire 'pstore'path = '/tmp/rb'class H      attr_accessor :a      attr_accessor :b      attr_accessor :c      def initialize                @a, @b, @c = 3, "abc", ["arr", "ay"]      end      public      def test                @c.join      endend#写入ps = PStore.new(path)ps.transaction {|x|      x['H'] = H.new}ps = nil#读取PStore.new(path).transaction {|x|      h = x['H']      puts h.a      puts h.b      puts h.test}

YAML 也可以被 PS,

拉郎配, 生硬
页: [1]
查看完整版本: PStore Meets YAML