Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created February 24, 2012 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sixeight/1896800 to your computer and use it in GitHub Desktop.
Save Sixeight/1896800 to your computer and use it in GitHub Desktop.
# 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