TopLevel Delegate

  • Thread starter trans. (T. Onoma)
  • Start date
T

trans. (T. Onoma)

Hi -- I'm trying to delegate the TOPLEVEL object through a singleton class,
but it doesn't seem to want to "singularize". I've tried the Singleton module
and manually as below. When I run this:

assert_equal( toplevel , toplevel )

I get

1) Failure:
test_compare(TC_TopLevel) [tc_toplevel.rb:16]:
<main> expected but was
<main>.

Any ideas?

Thanks,
T.


# toplevel.rb -------------------------------------------

class Binding
def eval( str )
Kernel.eval( str, self )
end

def self()
@self ||= eval( "self" )
@self
end
end

#require 'singleton'
require 'delegate'

class TopLevelClass < DelegateClass(TOPLEVEL_BINDING.self.class)
#include Singleton
class << self
private :new
def instance
@singleton ||= new
end
end
def initialize()
super( TOPLEVEL_BINDING.self )
end
def binding()
TOPLEVEL_BINDING
end
end

module Kernel
# perhaps just call this top() ?
def toplevel()
TopLevelClass.instance
end
end
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top