Skip to content

Instantly share code, notes, and snippets.

@tosik
Created October 8, 2012 08:18
Show Gist options
  • Select an option

  • Save tosik/3851363 to your computer and use it in GitHub Desktop.

Select an option

Save tosik/3851363 to your computer and use it in GitHub Desktop.

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
@ddrscott
Copy link

ddrscott commented Jan 2, 2013

I have the same issue with JSONKit objects.

https://gist.github.com/b501793ba3d29e0fd3e2

Have you found a fix for your issue?

@tosik
Copy link
Author

tosik commented Feb 7, 2013

no i dont.

i found an escaping method. this is JSON stringify and decode.
but it is not perfect ;(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment