Last active
December 10, 2015 05:08
-
-
Save acook/4385161 to your computer and use it in GitHub Desktop.
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
def extract_state object | |
state = { local_variables: {}, instance_variables: {} } | |
object_binding = object.send :binding | |
puts eval('local_variables', object_binding) | |
eval('local_variables', object_binding).each do |variable| | |
state[:local_variables][variable] = eval "#{variable}", object_binding | |
end | |
eval('instance_variables', object_binding).each do |variable| | |
state[:instance_variables][variable] = object_binding.instance_variable_get variable | |
end | |
state.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment