Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created July 24, 2012 22:11
Show Gist options
  • Save xaviervia/3173016 to your computer and use it in GitHub Desktop.
Save xaviervia/3173016 to your computer and use it in GitHub Desktop.
Dictionary class based on SymbolTable
# This class has been implemented into a gem rebuilding SymbolTable from the ground. It's called "SymbolMatrix"
# http://github.com/Fetcher/symbolmatrix
# Stupid but really useful class:
# Inherits from SymbolTable (https://github.com/mjijackson/symboltable), but when it is initialized
# it simply... well, recursively converts all Hashes into dictionaries
class Dictionary < SymbolTable
def initialize *args
super *args
_symbolize!
end
private
def _symbolize!
each_key do |key|
if self[key].instance_of? Hash
self[key] = Dictionary.new self[key]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment