Created
December 6, 2011 13:56
-
-
Save bolthar/1438286 to your computer and use it in GitHub Desktop.
Marshalling
This file contains 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
class Test | |
attr_reader :value | |
def self.value_by_block(&block) | |
@evaluator = block | |
end | |
def initialize | |
@value = self.class.instance_variable_get(:@evaluator).call | |
end | |
end | |
class TestSubClass < Test | |
value_by_block { 2 + 2 } | |
end | |
my_instance = TestSubClass.new | |
p my_instance.value | |
p my_instance.class.instance_variable_get(:@evaluator) | |
data = Marshal.dump(my_instance) | |
my_reloaded_instance = Marshal.load(data) | |
p my_reloaded_instance.value | |
p my_reloaded_instance.class.instance_variable_get(:@evaluator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment