[前][次][番号順一覧][スレッド一覧]

ruby-changes:65266

From: David <ko1@a...>
Date: Tue, 16 Feb 2021 18:11:39 +0900 (JST)
Subject: [ruby-changes:65266] 02151dad1b (master): `$LOAD_PATH.resolve_feature_path` should not raise

https://git.ruby-lang.org/ruby.git/commit/?id=02151dad1b

From 02151dad1ba324fac5f8e9459334164d01893124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sun, 4 Aug 2019 13:09:30 +0200
Subject: `$LOAD_PATH.resolve_feature_path` should not raise

I think it's more friendly and easier to work with to return `nil` when
the feature is not found in the $LOAD_PATH.
---
 load.c                    | 2 +-
 test/ruby/test_require.rb | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/load.c b/load.c
index cf3adcb..d6616fc 100644
--- a/load.c
+++ b/load.c
@@ -991,7 +991,7 @@ rb_resolve_feature_path(VALUE klass, VALUE fname) https://github.com/ruby/ruby/blob/trunk/load.c#L991
         sym = ID2SYM(rb_intern("so"));
         break;
       default:
-        load_failed(fname);
+        return Qnil;
     }
 
     return rb_ary_new_from_args(2, sym, path);
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 30c07b9..973d9c9 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -857,5 +857,9 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L857
       $:.replace(paths)
       $".replace(loaded)
     end
+
+    def test_resolve_feature_path_with_missing_feature
+      assert_nil($LOAD_PATH.resolve_feature_path("superkalifragilisticoespialidoso"))
+    end
   end
 end
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]