Skip to content

Instantly share code, notes, and snippets.

@jocke
Created February 10, 2014 08:50
Show Gist options
  • Save jocke/8912500 to your computer and use it in GitHub Desktop.
Save jocke/8912500 to your computer and use it in GitHub Desktop.
OxRUG 12 Feb 2014
# 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
@jopotts
Copy link

jopotts commented Feb 12, 2014

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 than fruit[: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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment