RubyMotion で Marshal.load(Marshal.dump(obj)) しても obj の深いクローンが再現されないケースがある。
RubyMotion と ruby1.9 で bug.rb を実行すると二つの環境で挙動に違いがある。 RubyMotion 上では Hash を継承したクラスの property が Marshal.dump されないみたいだ。
RubyMotion で Marshal.load(Marshal.dump(obj)) しても obj の深いクローンが再現されないケースがある。
RubyMotion と ruby1.9 で bug.rb を実行すると二つの環境で挙動に違いがある。 RubyMotion 上では Hash を継承したクラスの property が Marshal.dump されないみたいだ。
| class AppDelegate | |
| def application(application, didFinishLaunchingWithOptions:launchOptions) | |
| Bug.run | |
| true | |
| end | |
| end |
| class Foo < ::Hash | |
| attr_accessor :property | |
| end | |
| class Bug | |
| def self.run | |
| foo = Foo.new | |
| foo.property = :sleep | |
| clone_foo = Marshal.load(Marshal.dump(foo)) | |
| p foo.property | |
| p clone_foo.property | |
| end | |
| end |
| require 'bug' | |
| Bug.run |
no i dont.
i found an escaping method. this is JSON stringify and decode.
but it is not perfect ;(
I have the same issue with JSONKit objects.
https://gist.github.com/b501793ba3d29e0fd3e2
Have you found a fix for your issue?