Skip to content

Instantly share code, notes, and snippets.

@rfletcher
Forked from wmw/to_hash.rb
Created February 3, 2011 00:15
Show Gist options
  • Save rfletcher/808798 to your computer and use it in GitHub Desktop.
Save rfletcher/808798 to your computer and use it in GitHub Desktop.
class Balls
def initialize()
@name = 'blah'
@caption = 'blah'
end
def to_hash
self.instance_variables.inject({}) do |a, e|
a[e[1..-1].to_sym] = self.instance_variable_get(e)
a
end
end
end
@rfletcher
Copy link
Author

lil shorter. "better"? dunno.

@rfletcher
Copy link
Author

oh yeah, this might be better only because i didn't use Hash#symbolize_keys!, which is a Rails extension

@wmw
Copy link

wmw commented Feb 3, 2011

Thanks rick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment