Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 #<Foo:0x007f854390e488>
Exception `NoMethodError' at (irb):1 - undefined method `to_a' for #<Foo:0x007f854390e488>
=> [#<Foo:0x007f854390e488>]
irb(main):004:0>
  • Loading branch information
tenderlove committed Nov 9, 2012
1 parent 3ae8d6d commit dd0040d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -288,18 +288,23 @@ def html?
@@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

Expand Down

0 comments on commit dd0040d

Please sign in to comment.