Skip to content

Instantly share code, notes, and snippets.

@deepak
Created May 7, 2013 08:52
Show Gist options
  • Select an option

  • Save deepak/5531231 to your computer and use it in GitHub Desktop.

Select an option

Save deepak/5531231 to your computer and use it in GitHub Desktop.
method defined on the eigenclass shadows the instance method
# method defined on the eigenclass shadows the instance method
require 'pp'
class A
def foo; "A"; end
end
a1 = A.new
a2 = A.new
mk = class << a1
self
end
pp mk.object_id == a1.object_id #=> false
class << a1
def foo; "meta"; end
end
pp a1.foo #=> "meta"
pp a2.foo #=> "A"
__END__
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin10.8.0]
false
"meta"
"A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment