Created
June 24, 2017 06:45
-
-
Save KelseyDH/2e46466778225fd0a386fc0ab8122f69 to your computer and use it in GitHub Desktop.
Examine all ruby instance variables within current context
This file contains hidden or 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 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