Sha256: e78c16abd663d37d08fdd2928963dd80ac14951de1813c2a37880d5175b5fb2c

Contents?: true

Size: 471 Bytes

Versions: 1

Compression:

Stored size: 471 Bytes

Contents

module Kernel
  # Optionally require a gem. If it is not available, <tt>nil</tt>
  # will be returned. Alternatively, a block can be provided with code
  # to run.
  #   require 'non_existent'
  #   #=> nil
  #
  #   require 'non_existent' do
  #     puts 'Something went wrong'
  #   end
  #   #=> Outputs 'Something went wrong'
  def require_optional(gem, &block) #:doc:
    require gem
  rescue LoadError
    block.call if block
  end

  private :require_optional
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shenanigans-1.0.13 lib/shenanigans/kernel/require_optional.rb