Method: MIME::Type#initialize
- Defined in:
- lib/mime/type.rb
permalink #initialize(content_type) {|_self| ... } ⇒ Type
Builds a MIME::Type object from the content_type
, a MIME Content Type value (e.g., “text/plain” or “application/x-eruby”). The constructed object is yielded to an optional block for additional configuration, such as associating extensions and encoding information.
-
When provided a Hash or a MIME::Type, the MIME::Type will be constructed with #init_with.
There are two deprecated initialization forms:
-
When provided an Array, the MIME::Type will be constructed using the first element as the content type and the remaining flattened elements as extensions.
-
Otherwise, the content_type will be used as a string.
Yields the newly constructed self
object.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/mime/type.rb', line 133 def initialize(content_type) # :yields: self @friendly = {} @obsolete = @registered = @provisional = false @preferred_extension = @docs = @use_instead = nil self.extensions = [] case content_type when Hash init_with(content_type) when Array MIME::Types.deprecated( class: MIME::Type, method: :new, pre: "when called with an Array", once: true ) self.content_type = content_type.shift self.extensions = content_type.flatten when MIME::Type init_with(content_type.to_h) else MIME::Types.deprecated( class: MIME::Type, method: :new, pre: "when called with a String", once: true ) self.content_type = content_type end self.encoding ||= :default self.xrefs ||= {} yield self if block_given? end |