[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Better name for instance bypass method?

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.

2 Answers

Ara.T.Howard

4/3/2006 10:48:00 PM

0

Trans

4/4/2006 12:35:00 AM

0

Very nice, Ara. I will use this!

Thanks,
T.