Better name for instance bypass method?

T

Trans

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.
 
A

ara.t.howard

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,100
Latest member
MelodeeFaj
Top