Permalink
Browse files

Ruby 1.9.2: explicitly raise NoMethodError for attempts at explicit c…

…oercion
  • Loading branch information...
1 parent b92ff78 commit 64082b350c90bdfe776461868b1e5414c2d2415a @jeremy jeremy committed Dec 6, 2009
@@ -230,6 +230,10 @@ def evaluate_attribute_method(attr_name, method_definition, method_name=attr_nam
# It's also possible to instantiate related objects, so a Client class belonging to the clients
# table with a +master_id+ foreign key can instantiate master through Client#master.
def method_missing(method_id, *args, &block)
+ if method_id == :to_ary
+ raise NoMethodError, "undefined method `to_ary' for #{inspect}:#{self.class}"
+ end
+
method_name = method_id.to_s
if self.class.private_method_defined?(method_name)
@@ -45,7 +45,7 @@ def id
def method_missing(method, *args, &block)
# Ruby 1.9.2: disallow explicit coercion via method_missing.
if method == :to_ary || method == :to_str
- super
+ raise NoMethodError, "undefined method `#{method}' for nil:NilClass"
elsif klass = METHOD_CLASS_MAP[method]
raise_nil_warning_for klass, method, caller
else

0 comments on commit 64082b3

Please sign in to comment.