Created
February 24, 2012 02:37
-
-
Save Sixeight/1896800 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
class Hoge | |
def prefix(prefix) | |
@prefix ||= [] | |
@prefix << prefix | |
end | |
def with_prefix(meth) | |
return [@prefix.pop, meth].join('_') | |
end | |
def foo | |
prefix :foo | |
self | |
end | |
def foo_piyo | |
'[foo]piyo' | |
end | |
def method_missing(meth, *args) | |
__send__(with_prefix(meth), *args) | |
rescue NoMethodError | |
super | |
end | |
end | |
p Hoge.new.foo.piyo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment