Skip to content

Instantly share code, notes, and snippets.

@stouset
Created February 26, 2010 19:07
Show Gist options
  • Save stouset/316034 to your computer and use it in GitHub Desktop.
Save stouset/316034 to your computer and use it in GitHub Desktop.
require 'monkey'
Monkey.see(Object) do
def metaclass
class << self; self; end
end
end
o1 = Object.new
o2 = Object.new
o1.metaclass rescue 'fail' # => "fail"
o2.metaclass rescue 'fail' # => "fail"
Monkey.patch(o1, :metaclass) { o1.metaclass } # => #<Class:#<Object:0x1011baf38>>
o1.metaclass rescue 'fail' # => "fail"
o2.metaclass rescue 'fail' # => "fail"
Monkey.patch(Object, :metaclass) do
o1.metaclass # => #<Class:#<Object:0x1011baf38>>
o2.metaclass # => #<Class:#<Object:0x1011baec0>>
end
o1.metaclass rescue 'fail' # => "fail"
o2.metaclass rescue 'fail' # => "fail"
Monkey.patch(Object, :metaclass)
o1.metaclass rescue 'fail' # => #<Class:#<Object:0x1011baf38>>
o2.metaclass rescue 'fail' # => #<Class:#<Object:0x1011baec0>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment