Created
September 13, 2011 18:49
-
-
Save webmat/1214677 to your computer and use it in GitHub Desktop.
Better Ruby Hash#to_s
This file contains hidden or 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
# 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