Ruby: marshal and unmarshal a variable, not an instance -



Ruby: marshal and unmarshal a variable, not an instance -

ok, ruby gurus, hard 1 describe in title, bear me explanation:

i'm looking pass string represents variable: not instance, not collection of properties create object, actual variable: handle object.

the reason dealing resources can located on filesystem, on network, or in-memory. want create uri handler can handle each of these in consistent manner, can have schemes eg.

file:// http:// ftp:// inmemory://

you idea. it's lastly 1 i'm trying figure out: there way string representation of reference object in ruby, , utilize string create new reference? i'm interested in marshalling reference, not object. ideally there taking object#object_id, easy plenty get, , using create new variable elsewhere refers same object. i'm aware fragile , unusual utilize case: works within 1 ruby process long there existing variable maintain object beingness garbage collected, both true inmemory scheme i'm developing.

the alternatives can think of are:

marshal whole object , cram uri, won't work because info in object image buffer - large create global or singleton purgatory area store variable retrieval later using e.g. hash of object_id:variable pairs. bit smelly, work.

any other thoughts, stackoverflowers?

there's objectspace._id2ref :

f = foo.new #=> #<foo:0x10036c9b8> f.object_id #=> 2149278940 objectspace._id2ref(2149278940) #=> #<foo:0x10036c9b8>

in add-on caveats garbage collection objectspace carries big performance penalty in jruby (so much it's disabled default)

ruby

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -