您在不同的終端視窗中有兩個打開的 IRB 外殼。第一個 shell 已經輸入了以下代碼:
class Apple
attr_reader :variety, :origin, :history
def initialize(**args)
@variety = args[:variety]
@origin = args[:origin]
@history = args[:history]
end
end
apple = Apple.new(variety: 'Honeycrisp', origin: 'Minnesota', history: 'Introduction to Market: 1991')
第二個 shell 已經輸入了以下代碼:
class Apple
attr_reader :variety, :origin, :history
def initialize(**args)
@variety = args[:variety]
@origin = args[:origin]
@history = args[:history]
end
end
在 shell(s) 中撰寫代碼,將物件 apple 從 shell 1 復制到 shell 2。獎勵:在不使用外部 Ruby 庫的情況下撰寫解決方案。
uj5u.com熱心網友回復:
您可以在一次終端運行中為此使用Marshal 。
Marshal.dump(apple)
復制回傳的字串。
str = [copied from the other terminal]
apple = Marshal.load(str)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471105.html
上一篇:我如何停止rails服務器?
