Skip to content

Commit 87879a8

Browse files
committedMar 1, 2018
Try out TruffleRuby's lazy RubyGems against the family.
1 parent 6c9e1ff commit 87879a8

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed
 

Diff for: ‎core/src/main/ruby/jruby/kernel/gem_prelude.rb

+50-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
1-
if defined?(Gem)
2-
begin
3-
require 'rubygems'
4-
rescue LoadError
5-
# For JRUBY-5333, gracefully fail to load, since stdlib may not be available
6-
warn 'RubyGems not found; disabling gems' if $VERBOSE
7-
else
1+
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0
6+
# GNU General Public License version 2
7+
# GNU Lesser General Public License version 2.1
8+
9+
module Kernel
10+
# Take this alias name so RubyGems will reuse this copy
11+
# and skip the method below once RubyGems is loaded.
12+
alias :gem_original_require :require
13+
14+
private def require(path)
815
begin
9-
gem 'did_you_mean'
10-
require 'did_you_mean'
11-
Gem.clear_paths
12-
rescue Gem::LoadError, LoadError
13-
end if defined?(DidYouMean)
16+
gem_original_require(path)
17+
rescue LoadError
18+
require 'rubygems'
19+
require path
20+
end
21+
end
22+
23+
private def gem(*args)
24+
require 'rubygems'
25+
gem(*args)
1426
end
1527
end
28+
29+
class Object
30+
autoload :Gem, 'rubygems'
31+
32+
# RbConfig is required by RubyGems, which makes it available in Ruby by default.
33+
# Autoload it since we do not load RubyGems eagerly.
34+
# autoload :RbConfig, 'rbconfig'
35+
# Defined by RbConfig
36+
# autoload :CROSS_COMPILING, 'rbconfig'
37+
end
38+
39+
# if defined?(Gem)
40+
# begin
41+
# require 'rubygems'
42+
# rescue LoadError
43+
# # For JRUBY-5333, gracefully fail to load, since stdlib may not be available
44+
# warn 'RubyGems not found; disabling gems' if $VERBOSE
45+
# else
46+
# begin
47+
# gem 'did_you_mean'
48+
# require 'did_you_mean'
49+
# Gem.clear_paths
50+
# rescue Gem::LoadError, LoadError
51+
# end if defined?(DidYouMean)
52+
# end
53+
# end

0 commit comments

Comments
 (0)
Please sign in to comment.