#require 'singleton'
require 'delegate'
require 'raspberry/new/binding'

class TopLevelClass < DelegateClass(TOPLEVEL_BINDING.self.class)
  #include Singleton  # doesn't seem to work with delegate
  class << self
    private :new
    def instance
      @singleton ||= new
    end
  end
  def initialize()
    super(TOPLEVEL_BINDING.self)
  end
  def binding()
    TOPLEVEL_BINDING
  end
  #def method_missing(sym, *args, &blk)
  #  TOPLEVEL_BINDING.self.send(sym, *args, &blk)
  #end
end

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

# assign constant
TOPLEVEL = TopLevelClass.instance