zookeeper
Some simple monkeypatches to ruby core classes
String
The string class now has an unindent method. This is useful for things like HERE docs.
Sample usage
This will produce a string with a two space indent
def some_large_string
" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584\u2584\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2580\u2580\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2580\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2580\n HERE\nend\n"
With unindent String monkey patch... no spaces
def some_large_string
" \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2584\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584\u2584\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2584\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2593\u2593\u2593\u2593\u2593\u2593\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2580\u2591\u2591\u2591\u2591\u2580\u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2580\n \u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\n \u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2584\u2580\u2591\u2588\u2580\u2580\u2591\u2591\u2591\u2591\u2580\u2588\u2580\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2584\u2580\u2580\u2591\n \u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2580\u2591\u2591\u2591\u2588\u2580\u2591\u2591\u2584\u2584\u2591\u2591\u2588\u2591\u2591\u2588\u2580\u2588\u2591\u2588\u2591\u2591\u2580\u2584\u2591\n \u2591\u2588\u2584\u2584\u2591\u2588\u2591\u2588\u2591\u2580\u2584\u2591\u2588\u2584\u2584\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2584\u2584\u2580\u2591\n \u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\u263B\u25C8\n HERE\nend\n".unindent
Hash
Hash#symbolize_keys!
Rails Hash method symbolize_keys! to turn keys of strings into symbols
Hash#deep_symbolize
Deep symbolize method to symbolize keys recursively See this gist for more information.
Symbolizes all of hash's keys and subkeys. Also allows for custom pre-processing of keys (e.g. downcasing, etc) if the block is given:
somehash.deep_symbolize { |key| key.downcase }
Usage
Either include it into global Hash class to make it available to all hashes, or extend only your own hash objects with this module.
Example 1:
class Hash
include DeepSymbolizable
end
Example 2:
myhash.extend DeepSymbolizable