Methods

Instance Public methods

class_eval(*args, &block)

class_eval on an object acts like singleton_class.class_eval.

📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/singleton_class.rb, line 5
  def class_eval(*args, &block)
    singleton_class.class_eval(*args, &block)
  end
🔎 See on GitHub

concern(topic, &module_definition)

A shortcut to define a toplevel concern, not within a module.

See Module::Concerning for more.

📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/concern.rb, line 11
  def concern(topic, &module_definition)
    Object.concern topic, &module_definition
  end
🔎 See on GitHub

enable_warnings()

Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.

📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 20
  def enable_warnings
    with_warnings(true) { yield }
  end
🔎 See on GitHub

silence_warnings()

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
📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 14
  def silence_warnings
    with_warnings(nil) { yield }
  end
🔎 See on GitHub

suppress(*exception_classes)

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'
📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 41
  def suppress(*exception_classes)
    yield
  rescue *exception_classes
  end
🔎 See on GitHub

with_warnings(flag)

Sets $VERBOSE for the duration of the block and back to its original value afterwards.

📝 Source code
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 26
  def with_warnings(flag)
    old_verbose, $VERBOSE = $VERBOSE, flag
    yield
  ensure
    $VERBOSE = old_verbose
  end
🔎 See on GitHub