Skip to content

Commit

Permalink
Ruby 1.9.2: explicitly raise NoMethodError for attempts at explicit c…
Browse files Browse the repository at this point in the history
…oercion
  • Loading branch information
jeremy committed Dec 7, 2009
1 parent b92ff78 commit 64082b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/attribute_methods.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/whiny_nil.rb
Expand Up @@ -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
Expand Down

0 comments on commit 64082b3

Please sign in to comment.