README.adoc in refinements-7.10.0 vs README.adoc in refinements-7.11.0
- old
+ new
@@ -20,10 +20,11 @@
* Array
* BigDecimal
* DateTime
* File
* Hash
+* IO
* Pathname
* String
* StringIO
== Requirements
@@ -77,19 +78,20 @@
[source,ruby]
----
gem "refinements", require: false
----
-…then require the specific refinement, as needed. Example:
+...then require the specific refinement, as needed. Example:
[source,ruby]
----
require "refinements/arrays"
require "refinements/big_decimals"
require "refinements/date_times"
require "refinements/files"
require "refinements/hashes"
+require "refinements/ios"
require "refinements/pathnames"
require "refinements/strings"
require "refinements/string_ios"
----
@@ -104,10 +106,11 @@
using Refinements::Arrays
using Refinements::BigDecimals
using Refinements::DateTimes
using Refinements::Files
using Refinements::Hashes
+ using Refinements::IOs
using Refinements::Pathnames
using Refinements::Strings
using Refinements::StringIOs
end
----
@@ -459,9 +462,72 @@
[source,ruby]
----
example = {unit: "221B", street: "Baker Street", city: "London", country: "UK"}
example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
+----
+
+==== IO
+
+===== .void
+
+Answers an IO stream which points to `/dev/null` in order to ignore any reads or writes to the
+stream. When given a block, the stream will automatically close upon block exit. When not given a
+block, you'll need to close the stream manually.
+
+[source,ruby]
+----
+io = IO.void
+io.closed? # => false
+
+io = IO.void { |void| void.write "nevermore" }
+io.closed? # => true
+----
+
+===== #squelch
+
+Temporarily ignores any reads/writes for current stream for all code executed within the block. When
+not given a block, it answers itself.
+
+[source,ruby]
+----
+io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
+io.squelch { io.write "Test" }
+io.reread # => ""
+----
+
+===== #redirect
+
+Redirects current stream to other stream when given a block. Without a block, the original stream is
+answered instead.
+
+[source,ruby]
+----
+io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
+other = IO.new IO.sysopen(Pathname("other.txt").to_s, "w+")
+
+io.redirect other # => `io`
+
+io.redirect(other) { |stream| stream.write "test" }
+ .close # => ""
+other.close # => "test"
+----
+
+===== #reread
+
+Answers full stream by rewinding to beginning of stream and reading all content.
+
+[source,ruby]
+----
+io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
+io.write "This is a test."
+
+io.reread # => "This is a test."
+io.reread 4 # => "This"
+
+buffer = "".dup
+io.reread(buffer: buffer)
+buffer # => "This is a test."
----
==== Pathname
===== Pathname