Created
September 3, 2010 09:39
-
-
Save PatrickLef/563683 to your computer and use it in GitHub Desktop.
This file contains 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
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