# File lib/active_support/core_ext/kernel/debugger.rb, line 11
11: def breakpoint
12: message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
13: defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
14: debugger
15: end
class_eval on an object acts like singleton_class.class_eval.
# File lib/active_support/core_ext/kernel/singleton_class.rb, line 10
10: def class_eval(*args, &block)
11: singleton_class.class_eval(*args, &block)
12: end
Starts a debugging session if ruby-debug has been loaded (call rails server —debugger to do load it).
# File lib/active_support/core_ext/kernel/debugger.rb, line 4 4: def debugger 5: message = "\n***** Debugger requested, but was not available (ensure ruby-debug is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n" 6: defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message) 7: end
Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.
# File lib/active_support/core_ext/kernel/reporting.rb, line 15
15: def enable_warnings
16: with_warnings(true) { yield }
17: end
Require a library with fallback to RubyGems. Warnings during library loading are silenced to increase signal/noise for application warnings.
# File lib/active_support/core_ext/kernel/requires.rb, line 6
6: def require_library_or_gem(library_name)
7: silence_warnings do
8: begin
9: require library_name
10: rescue LoadError => cannot_require
11: # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
12: begin
13: require 'rubygems'
14: rescue LoadError # => rubygems_not_installed
15: raise cannot_require
16: end
17: # 2. Rubygems is installed and loaded. Try to load the library again
18: begin
19: require library_name
20: rescue LoadError # => gem_not_installed
21: raise cannot_require
22: end
23: end
24: end
25: end
Silences any stream for the duration of the block.
silence_stream(STDOUT) do
puts 'This will never be seen'
end
puts 'But this will'
# File lib/active_support/core_ext/kernel/reporting.rb, line 39
39: def silence_stream(stream)
40: old_stream = stream.dup
41: stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
42: stream.sync = true
43: yield
44: ensure
45: stream.reopen(old_stream)
46: end
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
# File lib/active_support/core_ext/kernel/reporting.rb, line 10
10: def silence_warnings
11: with_warnings(nil) { yield }
12: end
Returns the object’s singleton class.
# File lib/active_support/core_ext/kernel/singleton_class.rb, line 3 3: def singleton_class 4: class << self 5: self 6: end 7: 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"
# File lib/active_support/core_ext/kernel/reporting.rb, line 56
56: def suppress(*exception_classes)
57: begin yield
58: rescue Exception => e
59: raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
60: end
61: end
Sets $VERBOSE for the duration of the block and back to its original value afterwards.
# File lib/active_support/core_ext/kernel/reporting.rb, line 20
20: def with_warnings(flag)
21: old_verbose, $VERBOSE = $VERBOSE, flag
22: yield
23: ensure
24: $VERBOSE = old_verbose
25: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.