@@ -22,7 +22,7 @@ def #{method}(*)
2222
2323 SET = Mimes . new
2424 EXTENSION_LOOKUP = { }
25- LOOKUP = Hash . new { | h , k | h [ k ] = Type . new ( k ) unless k . blank? }
25+ LOOKUP = { }
2626
2727 def self . []( type )
2828 return type if type . is_a? ( Type )
@@ -85,7 +85,7 @@ class << self
8585 Q_SEPARATOR_REGEXP = /;\s *q=/
8686
8787 def lookup ( string )
88- LOOKUP [ string ]
88+ LOOKUP [ string ] || Type . new ( string )
8989 end
9090
9191 def lookup_by_extension ( extension )
@@ -204,9 +204,12 @@ def unregister(symbol)
204204 end
205205 end
206206
207+ attr_reader :hash
208+
207209 def initialize ( string , symbol = nil , synonyms = [ ] )
208210 @symbol , @synonyms = symbol , synonyms
209211 @string = string
212+ @hash = [ @string , @synonyms , @symbol ] . hash
210213 end
211214
212215 def to_s
@@ -240,6 +243,13 @@ def ==(mime_type)
240243 end
241244 end
242245
246+ def eql? ( other )
247+ super || ( self . class == other . class &&
248+ @string == other . string &&
249+ @synonyms == other . synonyms &&
250+ @symbol == other . symbol )
251+ end
252+
243253 def =~( mime_type )
244254 return false if mime_type . blank?
245255 regexp = Regexp . new ( Regexp . quote ( mime_type . to_s ) )
@@ -262,6 +272,10 @@ def respond_to?(method, include_private = false) #:nodoc:
262272 super || method . to_s =~ /(\w +)\? $/
263273 end
264274
275+ protected
276+
277+ attr_reader :string , :synonyms
278+
265279 private
266280 def method_missing ( method , *args )
267281 if method . to_s =~ /(\w +)\? $/
0 commit comments