Created
July 31, 2012 19:58
-
-
Save roryokane/3219986 to your computer and use it in GitHub Desktop.
Hash with symbol access of Strings in Ruby – the start of an implementation
This file contains 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
# encoding: utf-8 | |
class HashWithSymbolAccessOfStrings < Hash | |
def [](key) | |
begin | |
self.fetch key | |
rescue KeyError | |
string_key = key.to_s | |
if string_key != key | |
self[string_version] | |
else | |
self.default(key) | |
end | |
end | |
end | |
def []=(key, value) | |
# should work for new keys and overwriting | |
end | |
def fetch(*args) | |
# do I have to override this, too? And all of the other fetching methods? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment