Skip to content

Instantly share code, notes, and snippets.

@bolthar
Created December 6, 2011 13:56
Show Gist options
  • Save bolthar/1438286 to your computer and use it in GitHub Desktop.
Save bolthar/1438286 to your computer and use it in GitHub Desktop.
Marshalling
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