mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Improved the whiny nil #1600 [Nicholas Seckar]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -19,20 +19,20 @@ class NilClass
|
||||
end
|
||||
|
||||
def id
|
||||
raise "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_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
|
||||
|
||||
private
|
||||
def method_missing(method, *args, &block)
|
||||
if @@method_class_map.include?(method)
|
||||
raise_nil_warning_for @@method_class_map[method]
|
||||
raise_nil_warning_for @@method_class_map[method], caller
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def raise_nil_warning_for(klass)
|
||||
raise NoMethodError, NIL_WARNING_MESSAGE % klass
|
||||
def raise_nil_warning_for(klass, with_caller = nil)
|
||||
raise NoMethodError, NIL_WARNING_MESSAGE % klass, with_caller || caller
|
||||
end
|
||||
|
||||
NIL_WARNING_MESSAGE = <<-end_message unless const_defined?(:NIL_WARNING_MESSAGE)
|
||||
|
||||
Reference in New Issue
Block a user