Created
November 24, 2009 00:26
-
-
Save carlhuda/241510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def irb_load(fn, priv = nil) | |
path = search_file_from_ruby_path(fn) | |
raise LoadError, "No such file to load -- #{fn}" unless path | |
load_file(path, priv) | |
end | |
def search_file_from_ruby_path(fn) | |
if /^#{Regexp.quote(File::Separator)}/ =~ fn | |
return fn if File.exist?(fn) | |
return nil | |
end | |
for path in $: | |
if File.exist?(f = File.join(path, fn)) | |
return f | |
end | |
end | |
return nil | |
end | |
def load_file(path, priv = nil) | |
irb.with_path(path, File.basename(path)) do | |
if priv | |
ws = WorkSpace.new(Module.new) | |
else | |
ws = WorkSpace.new | |
end | |
irb.with_workspace(ws) do | |
irb.with_input_method(FileInputMethod.new(path)) do |io| | |
irb.with_signal_status(:IN_LOAD) do | |
if old_io.kind_of?(FileInputMethod) | |
irb.eval_input | |
else | |
begin | |
irb.eval_input | |
rescue LoadAbort | |
print "load abort!!\n" | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?") | |
return false if $".find{|f| f =~ rex} | |
case file_name | |
when /\.rb$/ | |
begin | |
if irb_load(file_name) | |
$".push file_name | |
return true | |
end | |
rescue LoadError | |
end | |
when /\.(so|o|sl)$/ | |
return ruby_require(file_name) | |
end | |
begin | |
irb_load(f = file_name + ".rb") | |
$".push f | |
return true | |
rescue LoadError | |
return ruby_require(file_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment