module SceneSwitcher

Constants

VERSION

Public Instance Methods

cache(file, priv = false) click to toggle source
# File lib/scene_switcher.rb, line 24
def cache(file, priv = false)
  begin
    expr = File.binread(file)
  rescue
    raise LoadError, "cannot load such file -- #{file}"
  end
  encoding = "UTF-8"
  encoding = $1 if expr.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
  expr.force_encoding(encoding)
  if priv
    @proc_cache[file] = eval("Proc.new {\nmodule Module.new::SceneSwitcherTemporaryModule\n#{expr}\nend\n}", Object::TOPLEVEL_BINDING, file, -1)
  else
    @proc_cache[file] = eval("Proc.new {\n#{expr}\n}", Object::TOPLEVEL_BINDING, file, 0)
  end
end
force_gc() click to toggle source
# File lib/scene_switcher.rb, line 18
def force_gc
  tmp_gc_disable = GC.enable
  GC.start
  GC.disable if tmp_gc_disable
end
gc_on_switch() click to toggle source
# File lib/scene_switcher.rb, line 10
def gc_on_switch
  @gc_on_switch
end
gc_on_switch=(bool) click to toggle source
# File lib/scene_switcher.rb, line 14
def gc_on_switch=(bool)
  @gc_on_switch = bool
end
switch_to(file, priv = false) click to toggle source
# File lib/scene_switcher.rb, line 40
def switch_to(file, priv = false)
  if @file
    @file = file
    throw :sceneswitcher_switch_signal
  else
    @file = file
    while @file
      force_gc if @gc_on_switch
      catch(:sceneswitcher_switch_signal) do
        cache(@file, priv) unless @proc_cache[@file]
        @proc_cache[@file].call
        @file = nil
      end
    end
    exit
  end
end