English 中文(简体)
页: 1
原标题:Ruby: marshal and unmarshal a variable, not an instance
  • 时间:2012-01-14 00:33:18
  •  标签:
  • ruby

在标题中很难描述这一点。

I m 想通过一个可变体:不是一种实例,不是收集构成物体的财产,而是实际变量:handle至物体。

The reason for this is that I am dealing with resources that can be located on the filesystem, on the network, or in-memory. I want to create URI handler that can handle each of these in a consistent manner, so I can have schemes like eg.

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

你们有这个想法。 这是我试图指出的最后一个例子:是否在某种程度上可以表明在Ruby提到物体的情况,然后利用这种说法来制定新的参考? 我确实有兴趣对参引<>,而不是object表示兴趣。 理想的情况是,采用<条码>目标#object_id等,这种编号很容易获得,并用它来在其他地方产生一个新变量,提及同一目标。 我知道,这确实可能很脆弱,因此是一种不寻常的使用案例:只要现有变数使物体不再被收集的垃圾,它就只能在一个鲁比拉进程内开展工作,但两者都是在<代码>inmemory上。 计划一米发展。

The only alternatives I can think of are:

  • marshal the whole object and cram it into the URI, but that won t work because the data in the object is an image buffer - very large
  • Create a global or singleton purgatory area to store a variable for retrieval later using e.g. a hash of object_id:variable pairs. This is a bit smelly, but would work.

任何其他想法,StackOverflowers?

最佳回答

The s Object Space._id2ref:

f = Foo.new #=> #<Foo:0x10036c9b8> 
f.object_id #=> 2149278940 
ObjectSpace._id2ref(2149278940) #=> #<Foo:0x10036c9b8>

除停车场收集点外,<代码> 物体空间对jruby(大体如此,以致于因违约而残疾)处以重刑。

问题回答

易变器是鲁比拉的 objects。 你们不仅不能与他们结婚,而且可以与他们一道工作。 你只能做一些与物体有关的事情,这些变量为t。

(really) ice objects





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...