Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created February 24, 2014 07:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tagomoris/9183222 to your computer and use it in GitHub Desktop.
Save tagomoris/9183222 to your computer and use it in GitHub Desktop.
class Foo
def self.foo
"foo"
end
def foo
"ifoo"
end
def true_foo
Foo.foo
end
end
module Interceptor
refine Foo.singleton_class do
def foo
"bar"
end
end
refine Foo do
def foo
"ibar"
end
end
end
using Interceptor
p Foo.foo # "bar"
p Foo.new.foo # "ibar"
p Foo.new.true_foo # "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment