Skip to content

Instantly share code, notes, and snippets.

@KelseyDH
Created June 24, 2017 06:45
Show Gist options
  • Save KelseyDH/2e46466778225fd0a386fc0ab8122f69 to your computer and use it in GitHub Desktop.
Save KelseyDH/2e46466778225fd0a386fc0ab8122f69 to your computer and use it in GitHub Desktop.
Examine all ruby instance variables within current context
class A
attr_accessor :foo, :bar
def context
self.instance_variables.map do |attribute|
{ attribute => self.instance_variable_get(attribute) }
end
end
end
a = A.new
a.foo = "foo"
a.bar = 42
a.context #=> [{ :@foo => "foo" }, { :@bar => 42 }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment