Skip to content

Instantly share code, notes, and snippets.

@yagince
Created April 23, 2013 13:11
Show Gist options
  • Select an option

  • Save yagince/5443440 to your computer and use it in GitHub Desktop.

Select an option

Save yagince/5443440 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
module HashExtensions
refine Hash do
def method_missing(name, *args)
self[name] || self[name.to_s] || super
end
end
end
using HashExtensions # 匿名モジュール内じゃないとusingできない
hash = { a: "hoge", "b" => "foo" }
p hash.a # => "hoge"
p hash.b # => "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment