Module: ZipKit::WriteShovel
- Included in:
- BlockWrite, StreamCRC32, Streamer, Streamer::DeflatedWriter, Streamer::StoredWriter, Streamer::Writable, WriteAndTell
- Defined in:
- lib/zip_kit/write_shovel.rb
Overview
A lot of objects in ZipKit accept bytes that may be sent
to the <<
operator (the "shovel" operator). This is in the tradition
of late Jim Weirich and his Builder gem. In this presentation
he justifies this design very eloquently. In ZipKit we follow this example.
However, there is a number of methods in Ruby - including the standard library -
which expect your object to implement the write
method instead. Since the write
method can be expressed in terms of the <<
method, why not allow all ZipKit
"IO-ish" things to also respond to write
? This is what this module does.
Jim would be proud. We miss you, Jim.
Instance Method Summary collapse
-
#write(bytes) ⇒ Fixnum
Writes the given data to the output stream.
Instance Method Details
#write(bytes) ⇒ Fixnum
Writes the given data to the output stream. Allows the object to be used as
a target for IO.copy_stream(from, to)
18 19 20 21 |
# File 'lib/zip_kit/write_shovel.rb', line 18 def write(bytes) self << bytes bytes.bytesize end |