aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/name_error.rb
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2015-01-03 14:58:17 +0000
committerVijay Dev <vijaydev.cse@gmail.com>2015-01-03 14:58:17 +0000
commit4b9dba99d65b1bd27576b16a68d7d18522bae9ea (patch)
tree4672dd2377a4e4ef71992c5478f2606f5d86e371 /activesupport/lib/active_support/core_ext/name_error.rb
parent02e72a49d1c99084fef2c78c3a194e03b879099d (diff)
parent7cc145ec65167084e8b05d9462eaf94534fa0168 (diff)
downloadrails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.tar.gz
rails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.tar.bz2
rails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.zip
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'activesupport/lib/active_support/core_ext/name_error.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/name_error.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/name_error.rb b/activesupport/lib/active_support/core_ext/name_error.rb
index e1ebd4f91c..b82148e4e5 100644
--- a/activesupport/lib/active_support/core_ext/name_error.rb
+++ b/activesupport/lib/active_support/core_ext/name_error.rb
@@ -1,5 +1,12 @@
class NameError
# Extract the name of the missing constant from the exception message.
+ #
+ # begin
+ # HelloWorld
+ # rescue NameError => e
+ # e.missing_name
+ # end
+ # # => "HelloWorld"
def missing_name
if /undefined local variable or method/ !~ message
$1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
@@ -7,6 +14,13 @@ class NameError
end
# Was this exception raised because the given name was missing?
+ #
+ # begin
+ # HelloWorld
+ # rescue NameError => e
+ # e.missing_name?("HelloWorld")
+ # end
+ # # => true
def missing_name?(name)
if name.is_a? Symbol
last_name = (missing_name || '').split('::').last