Skip to content

Instantly share code, notes, and snippets.

@anujluthra
Created January 31, 2011 07:21
Show Gist options
  • Save anujluthra/803733 to your computer and use it in GitHub Desktop.
Save anujluthra/803733 to your computer and use it in GitHub Desktop.
# error occurs when same lexical method (which calls super)
# is defined on the singleton class of two or more objects of different classes,
# and then that method is called on any of the objects
# other than the last one the method was defined on...
def x(obj)
# uncomment eval and it works
# eval "
class << obj
def to_s
super
end
end
# "
end
class C1;end
class C2;end
class C3;end
o1=C1.new
o2=C2.new
o3=C3.new
# copy paste x() code for each object rather calling x() and it works
x(o1)
x(o2)
x(o3)
o3.to_s
o2.to_s # raises: in `to_s': super from singleton method that is defined to multiple classes is not supported; this will be fixed in 1.9.3 or later (NotImplementedError)
o1.to_s # also would raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment