[ruby-core:95286] [Ruby master Feature#16246] require with an optional block that is evaluated when requiring fails
From:
sawadatsuyoshi@...
Date:
2019-10-09 05:54:24 UTC
List:
ruby-core #95286
Issue #16246 has been reported by sawa (Tsuyoshi Sawada).
----------------------------------------
Feature #16246: require with an optional block that is evaluated when requiring fails
https://bugs.ruby-lang.org/issues/16246
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I have some code like this:
```ruby
begin
require "foo"
rescue LoadError
puts "You need to install foo in order to have the function A work."
...
end
```
I request to allow `require` to take a block which is executed when requiring fails. When `require` takes a block, a `LoadError` would not be raised. The code above would then be written like:
```ruby
require "foo" do
puts "You need to install foo in order to have the function A work."
...
end
```
If there is no need to particularly do anything, then it can be like
```ruby
require("foo"){}
```
which will cover the use case in https://bugs.ruby-lang.org/issues/14565.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>