aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorclaudiob <claudiob@gmail.com>2014-12-25 00:50:13 +0100
committerclaudiob <claudiob@gmail.com>2014-12-25 00:50:13 +0100
commita5644d14ffbdc1b8cfceb83e3644efdf01caa0e0 (patch)
tree6bf919f89745424e28a9fcfa259a5cb149ff1d4a /activesupport
parentbea61d66708d293ee75733ddd912dc1331fa1834 (diff)
downloadrails-a5644d14ffbdc1b8cfceb83e3644efdf01caa0e0.tar.gz
rails-a5644d14ffbdc1b8cfceb83e3644efdf01caa0e0.tar.bz2
rails-a5644d14ffbdc1b8cfceb83e3644efdf01caa0e0.zip
Better docs for NameError
Add examples for missing_name, missing_name? [ci skip]
Diffstat (limited to 'activesupport')
-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