diff options
Diffstat (limited to 'activesupport/lib/active_support/whiny_nil.rb')
-rw-r--r-- | activesupport/lib/active_support/whiny_nil.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index f614b41fc7..983a14fd42 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -18,6 +18,7 @@ class NilClass methods.each { |method| @@method_class_map[method.to_sym] = class_name } end + # Raises a RuntimeError when you attempt to call id on nil or a nil object. def id raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller end @@ -27,6 +28,7 @@ class NilClass raise_nil_warning_for @@method_class_map[method], method, caller end + # Raises a NoMethodError when you attempt to call a method on nil, or a nil object. def raise_nil_warning_for(class_name = 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 #{class_name}." if class_name |