1 # Add a +missing_name+ method to NameError instances.
2 class NameError #:nodoc:
3 # Add a method to obtain the missing name from a NameError.
4 def missing_name
5 if /undefined local variable or method/ !~ message
6 $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
7 end
8 end
9
10 # Was this exception raised because the given name was missing?
11 def missing_name?(name)
12 if name.is_a? Symbol
13 last_name = (missing_name || '').split('::').last
14 last_name == name.to_s
15 else
16 missing_name == name.to_s
17 end
18 end
19 end