модуль Kernel
Открытые методы экземпляров
# File activesupport/lib/active_support/core_ext/kernel/singleton_class.rb, line 3 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 9 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 18
def enable_warnings
with_warnings(true) { yield }
end Устанавливает $VERBOSE в true на время выполнения блока и возвращает к исходному значению после.
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 12
def silence_warnings
with_warnings(nil) { yield }
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 39 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 24 def with_warnings(flag) old_verbose, $VERBOSE = $VERBOSE, flag yield ensure $VERBOSE = old_verbose end
Устанавливает $VERBOSE на время выполнения блока и возвращает к исходному значению после.
© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.