From 43c34e20d2698e04c398496e4cbc4e2271619297 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Sat, 15 Oct 2005 02:24:05 +0000 Subject: Updated whiny nil to be more concise and useful. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2602 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/whiny_nil.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'activesupport/lib/active_support/whiny_nil.rb') diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index 9beba568c7..61cbe98e2b 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -24,23 +24,15 @@ class NilClass private def method_missing(method, *args, &block) - if @@method_class_map.include?(method) - raise_nil_warning_for @@method_class_map[method], caller - else - super - end + raise_nil_warning_for @@method_class_map[method], method, caller end - def raise_nil_warning_for(klass, with_caller = nil) - raise NoMethodError, NIL_WARNING_MESSAGE % klass, with_caller || caller + def raise_nil_warning_for(klass = nil, selector = nil, with_caller = nil) + message = "You have a nil object when you didn't expect it!" + message << "\nYou might have expected an instance of #{klass}." if klass + message << "\nThe error occured while evaluating nil.#{selector}" if selector + + raise NoMethodError, message, with_caller || caller end - - NIL_WARNING_MESSAGE = <<-end_message unless const_defined?(:NIL_WARNING_MESSAGE) -WARNING: You have a nil object when you probably didn't expect it! Odds are you -want an instance of %s instead. - -Look in the callstack to see where you're working with an object that could be nil. -Investigate your methods and make sure the object is what you expect! - end_message end -- cgit v1.2.3