Skip to content

Instantly share code, notes, and snippets.

@PatrickLef
Created September 3, 2010 09:39
Show Gist options
  • Save PatrickLef/563683 to your computer and use it in GitHub Desktop.
Save PatrickLef/563683 to your computer and use it in GitHub Desktop.
module Utils
# Creates a hash from instance vars
def attributes
vars = {}
instance_variables.each do |var|
vars[var.gsub("@", "").to_sym] = instance_variable_get(var)
end
vars
end
end
class User
include Utils
def initialize
@animal = "fisk"
@foo = "bar"
end
end
u = User.new
p u.attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment