From dd0040d19f2b161201fd54e21fc807fb987f016d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 9 Nov 2012 14:28:22 +0900 Subject: implement to_a and to_ary so that the Array() call in template.rb will not raise so many exceptions: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/template.rb#L126 irb(main):001:0> class Foo; def method_missing(*args); super; end end => nil irb(main):002:0> $DEBUG = true => true irb(main):003:0> Array(Foo.new) Exception `NoMethodError' at (irb):1 - undefined method `to_ary' for # Exception `NoMethodError' at (irb):1 - undefined method `to_a' for # => [#] irb(main):004:0> --- actionpack/lib/action_dispatch/http/mime_type.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch/http/mime_type.rb') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 2b5d3d85bf..f56f09c5b3 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -288,18 +288,23 @@ module Mime @@html_types.include?(to_sym) || @string =~ /html/ end + private - def method_missing(method, *args) - if method.to_s.ends_with? '?' - method[0..-2].downcase.to_sym == to_sym - else - super - end - end - def respond_to_missing?(method, include_private = false) #:nodoc: - method.to_s.ends_with? '?' + def to_ary; end + def to_a; end + + def method_missing(method, *args) + if method.to_s.ends_with? '?' + method[0..-2].downcase.to_sym == to_sym + else + super end + end + + def respond_to_missing?(method, include_private = false) #:nodoc: + method.to_s.ends_with? '?' + end end end -- cgit v1.2.3