0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A few ruby core patches in a gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Manic Monkey

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

require 'manic_monkey'

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

Hash Accessors

Typical Useage: You need accessors to the level 1 keys of database stored serialized data, e.g. json, jsonb, xml

In your class that has the serialized db column

class AwesomeSauce
  hash_accessor :column_of_serialized_data, :key1, :key2

This should now allow you to call the method directly on an object created from the class

@object = AwesomeSauce.new
@object.key1

versus

@object = AwesomeSauce.new
@object.column_of_serialized_data[:key1]