Trans
4/3/2006 10:15:00 PM
Ths is used inside an object that clears out most of the Kernel methods
(like BlankSlate). It allows one to get at those methods.
class BasicObject
# ... undefines Kernel methods ...
class Instance < self
define_method( :method_missing ) do |meth, *args| # &blk|
Kernel.instance_method(meth).bind(self).call(*args) # ,&blk)
end
end
def instance
@__instance__ ||= Instance.new
end
end
For example:
class A < BasicObject
end
a = A.new
a.class #=> NoMethodError
a.instance.class #=> A
I would be happy with the name "instance" except it does minorly
conflict with Singleton (not the eigenclass kind). Anyone have a better
suggestion for the name. Note, I originally choice "instance" because
of other methods like #instance_variables.
Thanks,
T.