vendor/rails/activesupport/lib/active_support/whiny_nil.rb in radiant-0.8.2 vs vendor/rails/activesupport/lib/active_support/whiny_nil.rb in radiant-0.9.0.rc2
- old
+ new
@@ -41,11 +41,18 @@
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)
- raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
+ # Ruby 1.9.2: disallow explicit coercion via method_missing.
+ if method == :to_ary || method == :to_str
+ super
+ elsif klass = METHOD_CLASS_MAP[method]
+ raise_nil_warning_for klass, method, caller
+ else
+ super
+ end
end
# Raises a NoMethodError when you attempt to call a method on +nil+.
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!"
@@ -53,6 +60,5 @@
message << "\nThe error occurred while evaluating nil.#{selector}" if selector
raise NoMethodError, message, with_caller || caller
end
end
-