Sha256: 0fc1d34d5e79c67402e866d598afa5b36a9bcd5e6c363b1e09a151aaa049da1f

Contents?: true

Size: 1.04 KB

Versions: 49

Compression:

Stored size: 1.04 KB

Contents

module Kernel
  module_function

  # Sets $VERBOSE to nil for the duration of the block and back to its original
  # value afterwards.
  #
  #   silence_warnings do
  #     value = noisy_call # no warning voiced
  #   end
  #
  #   noisy_call # warning voiced
  def silence_warnings
    with_warnings(nil) { yield }
  end

  # Sets $VERBOSE to +true+ for the duration of the block and back to its
  # original value afterwards.
  def enable_warnings
    with_warnings(true) { yield }
  end

  # Sets $VERBOSE for the duration of the block and back to its original
  # value afterwards.
  def with_warnings(flag)
    old_verbose, $VERBOSE = $VERBOSE, flag
    yield
  ensure
    $VERBOSE = old_verbose
  end

  # Blocks and ignores any exception passed as argument if raised within the block.
  #
  #   suppress(ZeroDivisionError) do
  #     1/0
  #     puts 'This code is NOT reached'
  #   end
  #
  #   puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
  def suppress(*exception_classes)
    yield
  rescue *exception_classes
  end
end

Version data entries

49 entries across 47 versions & 8 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.7.2 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.7.1 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.7 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.6 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.6.rc1 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.5 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.5.rc2 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.5.rc1 lib/active_support/core_ext/kernel/reporting.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.4 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.4.rc1 lib/active_support/core_ext/kernel/reporting.rb
activesupport-5.0.3 lib/active_support/core_ext/kernel/reporting.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/kernel/reporting.rb