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.
on 2006-04-04 02:20
on 2006-04-04 02:54
On Tue, 4 Apr 2006, Trans wrote: > end > end > > def instance > @__instance__ ||= Instance.new > end maybe class BasicObject Self = Class.new(self) do ... ... ... end def Self() @__self__ ||= Self.new end end so o = BasicObject.new o.Self.p 42 ?? in fact, you can even def self() @__self__ ||= Self.new end though that might be confusing, maybe... def __self__() @__self__ ||= Self.new end food for thought. regards. -a
on 2006-04-04 04:40
Very nice, Ara. I will use this! Thanks, T.