Spec-Zone.ru › Ruby on Rails 6.1

модуль Kernel

Общедоступные методы экземпляра

class_eval(*args, &block) Показать исходный код
# 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.

concern(topic, &module_definition) Показать исходный код
# 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 для более подробной информации.

enable_warnings() { || ... } Показать исходный код
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 20
def enable_warnings
  with_warnings(true) { yield }
end

Устанавливает $VERBOSE в true на время блока и возвращает к исходному значению после него.

silence_warnings() { || ... } Показать исходный код
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 14
def silence_warnings
  with_warnings(nil) { yield }
end

Устанавливает $VERBOSE в nil на время блока и возвращает к исходному значению после него.

silence_warnings do
  value = noisy_call # no warning voiced
end

noisy_call # warning voiced
suppress(*exception_classes) { || ... } Показать исходный код
# 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'
with_warnings(flag) { || ... } Показать исходный код
# 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–2020 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API