Forum: Ruby Better name for instance bypass method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Trans (Guest)
on 2006-04-04 02:20
(Received via mailing list)
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.
unknown (Guest)
on 2006-04-04 02:54
(Received via mailing list)
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
Trans (Guest)
on 2006-04-04 04:40
(Received via mailing list)
Very nice, Ara. I will use this!

Thanks,
T.
This topic is locked and can not be replied to.