Created
February 10, 2014 08:50
-
-
Save jocke/8912500 to your computer and use it in GitHub Desktop.
OxRUG 12 Feb 2014
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
# Just an academic snippet for OxRUG's meeting on | |
# 12th February 2014. The discussion could be | |
# about: | |
# - What does it do (quite pointless otherwise). | |
# - What are the dangers/drawbacks. | |
# - How it can be improved. | |
# - Does it have any function in real life. | |
# - Etc... | |
# | |
class Hash | |
def method_missing(method_name, *args, &block) | |
if self.has_key? method_name | |
self[method_name] | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A comment for discussion later...
I think the purpose is to be able to access hash elements via dot notation (because
fruit.apple
is prettier thanfruit[:apple]
).Going back a few months, that was why this emerged: https://gist.github.com/jopotts/7138478
Which leads to
Fruit.apple
(plus some other bonus features).Also I think hashery or perhaps facets enable this sort of behaviour, but haven't looked further.