Skip to content

Instantly share code, notes, and snippets.

@scott-ad-riley
Last active March 5, 2016 17:56
Show Gist options
  • Save scott-ad-riley/5e6783749f9fbdae4b0c to your computer and use it in GitHub Desktop.
Save scott-ad-riley/5e6783749f9fbdae4b0c to your computer and use it in GitHub Desktop.
Hash of Object Instance Variables (Ruby)
class myClass
# [initialize with instance variable assignments]
def to_hash
return Hash[self.instance_variables.map{|var_name| [var_name.to_s.delete("@"), eval(var_name.to_s)]}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment