Skip to content

Instantly share code, notes, and snippets.

@webmat
Created September 13, 2011 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save webmat/1214677 to your computer and use it in GitHub Desktop.
Save webmat/1214677 to your computer and use it in GitHub Desktop.
Better Ruby Hash#to_s
# Let's face it. Ruby's Hash#to_s output isn't very useful.
# Here's a draft for a better version.
class Hash
def to_s
keys.inject([]) do |a, key|
a << "#{key}: #{fetch(key)}"
end.join(', ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment