Skip to content

Instantly share code, notes, and snippets.

@eprothro
Last active October 25, 2017 14:44
Show Gist options
  • Select an option

  • Save eprothro/cd64d4d63609e232ee702d62a433d9f2 to your computer and use it in GitHub Desktop.

Select an option

Save eprothro/cd64d4d63609e232ee702d62a433d9f2 to your computer and use it in GitHub Desktop.
You can temporarily override (not overwrite) a ruby method for an object by defining a method on the object metaclass.
class Foo
def bar
:object_method
end
end
f = Foo.new
f.bar
# => :object_method
def f.bar
:object_metaclass_method
end
f.bar
# => :object_metaclass_method
class << f
remove_method(:bar)
end
f.bar
# => :object_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment