модуль Kernel
Открытые методы экземпляра
# 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
class_eval для объекта действует как singleton_class.class_eval.
# File activesupport/lib/active_support/core_ext/kernel/concern.rb, line 11 def concern(topic, &module_definition) Object.concern topic, &module_definition end
Сокращённый способ определить concern верхнего уровня, не внутри модуля.
Подробнее см. Module::Concerning.
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 20 def enable_warnings(&block) with_warnings(true, &block) end
На время выполнения блока устанавливает $VERBOSE в true, а после возвращает исходное значение.
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 14 def silence_warnings(&block) with_warnings(nil, &block) end
На время выполнения блока устанавливает $VERBOSE в nil, а после возвращает исходное значение.
silence_warnings do value = noisy_call # no warning voiced end noisy_call # warning voiced
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 41 def suppress(*exception_classes) yield rescue *exception_classes end
Перехватывает и игнорирует любое исключение, переданное в качестве аргумента, если оно возникает внутри блока.
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 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
На время выполнения блока устанавливает $VERBOSE, а после возвращает исходное значение.
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.