Module: RightSupport::Ruby::ObjectExtensions
- Included in:
- Object
- Defined in:
- lib/right_support/ruby/object_extensions.rb
Instance Method Summary collapse
-
#if_require_succeeds(*args) ⇒ Object
Attempt to require one or more source files; if the require succeeds (or if the files have already been successfully required), yield to the block.
Instance Method Details
#if_require_succeeds(*args) ⇒ Object
Attempt to require one or more source files; if the require succeeds (or if the files have already been successfully required), yield to the block.
This method is useful to conditionally define code depending on the availability of gems or standard-library source files.
Parameters
Uses a parameters glob to pass all of its parameters transparently through to Kernel#require.
Block
The block will be called if the require succeeds (if it does not raise LoadError).
Return
Preserves the return value of Kernel#require (generally either true or false).
18 19 20 21 22 23 24 |
# File 'lib/right_support/ruby/object_extensions.rb', line 18 def if_require_succeeds(*args) result = require(*args) yield if block_given? return result rescue LoadError => e return false end |