Module Kernel
In: vendor/rails/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb
vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb
vendor/rails/activesupport/lib/active_support/core_ext/kernel/requires.rb
vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb

Since Ruby is very dynamic, methods added to the ancestors of BlankSlate after BlankSlate is defined will show up in the list of available BlankSlate methods. We handle this by defining a hook in the Object and Kernel classes that will hide any method defined after BlankSlate has been loaded.

Methods

External Aliases

method_added -> blank_slate_method_added

Public Class methods

Detect method additions to Kernel and remove them in the BlankSlate class.

[Source]

    # File vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb, line 65
65:     def method_added(name)
66:       result = blank_slate_method_added(name)
67:       return result if self != Kernel
68:       BlankSlate.hide(name)
69:       result
70:     end

Public Instance methods

[Source]

    # File vendor/rails/activesupport/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

Turns the current script into a daemon process that detaches from the console. It can be shut down with a TERM signal.

[Source]

   # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb, line 4
4:   def daemonize
5:     Process.daemon
6:   end

Starts a debugging session if ruby-debug has been loaded (call script/server —debugger to do load it).

[Source]

   # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb, line 4
4:     def debugger
5:       message = "\n***** Debugger requested, but was not available: 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.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 17
17:   def enable_warnings
18:     old_verbose, $VERBOSE = $VERBOSE, true
19:     yield
20:   ensure
21:     $VERBOSE = old_verbose
22:   end

Require a library with fallback to RubyGems. Warnings during library loading are silenced to increase signal/noise for application warnings.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/requires.rb, line 4
 4:   def require_library_or_gem(library_name)
 5:     silence_warnings do
 6:       begin
 7:         require library_name
 8:       rescue LoadError => cannot_require
 9:         # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
10:         begin
11:           require 'rubygems'
12:         rescue LoadError => rubygems_not_installed
13:           raise cannot_require
14:         end
15:         # 2. Rubygems is installed and loaded. Try to load the library again
16:         begin
17:           require library_name
18:         rescue LoadError => gem_not_installed
19:           raise cannot_require
20:         end
21:       end
22:     end
23:   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'

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 36
36:   def silence_stream(stream)
37:     old_stream = stream.dup
38:     stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
39:     stream.sync = true
40:     yield
41:   ensure
42:     stream.reopen(old_stream)
43:   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

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 9
 9:   def silence_warnings
10:     old_verbose, $VERBOSE = $VERBOSE, nil
11:     yield
12:   ensure
13:     $VERBOSE = old_verbose
14:   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"

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 53
53:   def suppress(*exception_classes)
54:     begin yield
55:     rescue Exception => e
56:       raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
57:     end
58:   end

[Validate]