Project

General

Profile

Actions

Feature #16246

open

require with an optional block that is evaluated when requiring fails

Added by sawa (Tsuyoshi Sawada) about 5 years ago. Updated about 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:95286]

Description

I have some code like this:

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:

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

require("foo"){}

which will cover the use case in https://bugs.ruby-lang.org/issues/14565.

Actions

Also available in: Atom PDF

Like0
Like0