TOPLEVEL_BINDING = binding module RequireRelative def require_relative(path) @path ||= [] uri = URI.parse(JS.document.location.href.to_s) path = "#{path}.rb" unless path =~ /\.rb$/ uri.path = ['/lib', @path.last, path].join('/') uri.query = nil JS.global.fetch(uri.to_s) {|res| unless res.ok == true JS.global.alert("error #{res.status}") raise end @path.push File.dirname([@path.last, path].join('/')) text = res.text.await.to_s TOPLEVEL_BINDING.eval text @path.pop } end end module Kernel prepend RequireRelative end