Module: Tins::RequireMaybe
- Included in:
- Object
- Defined in:
- lib/tins/require_maybe.rb
Overview
A module that provides a safe require mechanism with optional error handling.
This module is included in Object, making the ‘require_maybe` method globally available throughout your Ruby application. It enables conditional loading of libraries where the failure to load a dependency is not necessarily an error condition, making it ideal for optional dependencies and feature detection.
Instance Method Summary collapse
-
#require_maybe(library) {|LoadError| ... } ⇒ Boolean
Attempts to require a library, gracefully handling LoadError exceptions.
Instance Method Details
#require_maybe(library) {|LoadError| ... } ⇒ Boolean
Attempts to require a library, gracefully handling LoadError exceptions.
This method is globally available because the module is included in Object. It’s particularly useful for optional dependencies and feature detection.
39 40 41 42 43 |
# File 'lib/tins/require_maybe.rb', line 39 def require_maybe(library) require library rescue LoadError => e block_given? and yield e end |