Spec-Zone.ru › Ruby on Rails 5.1

class NameError

Parent:
Object

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

missing_name() Показать исходный код
# File activesupport/lib/active_support/core_ext/name_error.rb, line 10
def missing_name
  if /undefined local variable or method/ !~ message
    $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
  end
end

Извлечь имя отсутствующей константы из сообщения об исключении.

begin
  HelloWorld
rescue NameError => e
  e.missing_name
end
# => "HelloWorld"
missing_name?(name) Показать исходный код
# File activesupport/lib/active_support/core_ext/name_error.rb, line 24
def missing_name?(name)
  if name.is_a? Symbol
    self.name == name
  else
    missing_name == name.to_s
  end
end

Было ли это исключение вызвано отсутствием указанного имени?

begin
  HelloWorld
rescue NameError => e
  e.missing_name?("HelloWorld")
end
# => true

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

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