Project

General

Profile

Feature #11140 ยป call_send_on_autoload.diff

tenderlovemaking (Aaron Patterson), 05/12/2015 12:24 AM

View differences:

test/ruby/test_autoload.rb
}
end
def test_require_implemented_in_ruby_is_called
kernel = class << Kernel; alias :old_require :require; self; end
called_with = []
kernel.send :define_method, :require do |path|
called_with << path
old_require path
end
Tempfile.create(['autoload', '.rb']) {|file|
file.puts 'class AutoloadTest; end'
file.close
add_autoload(file.path)
begin
assert(Object::AutoloadTest)
ensure
remove_autoload_constant
end
assert_equal [file.path], called_with
}
ensure
class << Kernel; alias :require :old_require; undef :old_require; end
end
def add_autoload(path)
(@autoload_paths ||= []) << path
eval <<-END
variable.c
autoload_require(VALUE arg)
{
struct autoload_data_i *ele = (struct autoload_data_i *)arg;
return rb_require_safe(ele->feature, ele->safe_level);
return rb_funcall(rb_mKernel, rb_intern("require"), 1, ele->feature);
}
static VALUE
    (1-1/1)