Skip to content

Instantly share code, notes, and snippets.

@acook
Last active December 10, 2015 05:08
Show Gist options
  • Save acook/4385161 to your computer and use it in GitHub Desktop.
Save acook/4385161 to your computer and use it in GitHub Desktop.
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