aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/name_error.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/name_error.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/name_error.rb15
1 files changed, 15 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
new file mode 100644
index 0000000000..42b89d3d28
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/name_error.rb
@@ -0,0 +1,15 @@
+
+# Add a +missing_name+ method to NameError instances.
+class NameError < StandardError
+
+ # Add a method to obtain the missing name from a NameError.
+ def missing_name
+ $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
+ end
+
+ # Was this exception raised because the given name was missing?
+ def missing_name?(name)
+ missing_name == name.to_s
+ end
+
+end \ No newline at end of file