module Kernel

def class_eval(*args, &block)

class_eval on an object acts like +singleton_class.class_eval+.
def class_eval(*args, &block)
  singleton_class.class_eval(*args, &block)
end

def concern(topic, &module_definition)

See Module::Concerning for more.

A shortcut to define a toplevel concern, not within a module.
def concern(topic, &module_definition)
  Object.concern topic, &module_definition
end

def enable_warnings(&block)

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

def silence_warnings(&block)

noisy_call # warning voiced

end
value = noisy_call # no warning voiced
silence_warnings do

value afterwards.
Sets $VERBOSE to +nil+ for the duration of the block and back to its original
def silence_warnings(&block)
  with_warnings(nil, &block)
end

def suppress(*exception_classes)

puts 'This code gets executed and nothing related to ZeroDivisionError was seen'

end
puts 'This code is NOT reached'
1/0
suppress(ZeroDivisionError) do

Blocks and ignores any exception passed as argument if raised within the block.
def suppress(*exception_classes)
  yield
rescue *exception_classes
end

def with_warnings(flag)

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