Class: MIME::Types::Container
- Inherits:
-
Hash
- Object
- Hash
- MIME::Types::Container
- Defined in:
- lib/mime/types/container.rb
Overview
MIME::Types requires a container Hash with a default values for keys resulting in an empty array ([]
), but this cannot be dumped through Marshal because of the presence of that default Proc. This class exists solely to satisfy that need.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
- #init_with(coder) ⇒ Object
-
#initialize ⇒ Container
constructor
:nodoc:.
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
Constructor Details
#initialize ⇒ Container
:nodoc:
8 9 10 11 |
# File 'lib/mime/types/container.rb', line 8 def initialize super self.default_proc = ->(h, k) { h[k] = Set.new } end |
Instance Method Details
#encode_with(coder) ⇒ Object
22 23 24 |
# File 'lib/mime/types/container.rb', line 22 def encode_with(coder) each { |k, v| coder[k] = v.to_a } end |
#init_with(coder) ⇒ Object
26 27 28 29 |
# File 'lib/mime/types/container.rb', line 26 def init_with(coder) self.default_proc = ->(h, k) { h[k] = Set.new } coder.map.each { |k, v| self[k] = Set[*v] } end |
#marshal_dump ⇒ Object
13 14 15 |
# File 'lib/mime/types/container.rb', line 13 def marshal_dump {}.merge(self) end |
#marshal_load(hash) ⇒ Object
17 18 19 20 |
# File 'lib/mime/types/container.rb', line 17 def marshal_load(hash) self.default_proc = ->(h, k) { h[k] = Set.new } merge!(hash) end |