Created
June 26, 2015 18:42
-
-
Save sshao/c54db68c9521c6bbd306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ ruby -v user_marshal.rb | |
| ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13] | |
| user_marshaled object | |
| original obj extends: [Extension, Kernel] | |
| unmarshaled obj extends: [Kernel] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ostruct' | |
| class Object | |
| # List modules extended by object | |
| def extended_modules | |
| (class << self; self end).included_modules | |
| end | |
| end | |
| def work(type, original, unmarshaled) | |
| puts type | |
| puts "original obj extends:\t\t#{original.extended_modules.inspect}" | |
| puts "unmarshaled obj extends:\t#{unmarshaled.extended_modules.inspect}" | |
| puts "\n" | |
| end | |
| class UserMarshaled | |
| def initialize(name) | |
| @name = name | |
| end | |
| def marshal_dump | |
| @name | |
| end | |
| def marshal_load(arg) | |
| @name = arg | |
| end | |
| end | |
| module Extension; end | |
| obj = UserMarshaled.new("object") | |
| obj.extend Extension | |
| unmarshaled_obj = Marshal.load(Marshal.dump(obj)) | |
| work("user_marshaled object", obj, unmarshaled_obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment