0
我在ruby中使用管道,我无法通过管道发送序列化对象。 我遇到了一个“NoMethodError”,这是因为我正在发送一个结构。 我试着添加一个函数,但是当我调用函数时,我得到了同样的错误。 是什么导致了这个问题,解决方案是什么?通过管道发送的对象序列化“NoMethodError”
来源:
reader, writer = IO.pipe
#define the pair object
Pair = Struct.new(:x, :y) do
end
#creates, serializes and sends an object
fork do
temp = Pair.new(1, 2)
temp_str = Marshal.dump(temp)
writer.puts temp_str
end
#prints it's contents
fork do
obj = reader.gets
puts obj.x
puts obj.y
end
注:我带的东西应该是什么样子,从第二个答案在这个线程的基本概念: Marshal (Ruby) pipes: sending serialized object to child processes
如果你有意将':ty'放置在你的结构中,那么看起来很明显,调用'#y'将不会成功,请澄清。 – Patru
我没有这是一个错字。现在编辑。 – Bloodcount