README.adoc in refinements-9.8.0 vs README.adoc in refinements-10.0.0
- old
+ new
@@ -126,32 +126,36 @@
example.combinatorial? [] # false
----
===== #compress
-Removes `nil` and empty objects without mutating itself.
+Removes `nil` and empty objects without mutating itself. Answers itself if there is nothing to remove.
[source,ruby]
----
object = Object.new
example = [1, "blueberry", nil, "", [], {}, object]
+[].compress # []
+[1, 2].compress # [1, 2]
example.compress # [1, "blueberry", object]
example # [1, "blueberry", nil, "", [], {}, object]
----
===== #compress!
-Removes `nil` and empty values while mutating itself.
+Removes `nil` and empty values while mutating itself. Answers `nil` if there is nothing to remove.
[source,ruby]
----
object = Object.new
example = [1, "blueberry", nil, "", [], {}, object]
-example.compress # [1, "blueberry", object]
-example # [1, "blueberry", object]
+[].compress! # nil
+[1, 2].compress! # nil
+example.compress! # [1, "blueberry", object]
+example # [1, "blueberry", object]
----
===== #excluding
Removes given array or elements without mutating itself.
@@ -217,11 +221,11 @@
Answers the maximum extracted value from a collection of objects.
[source,ruby]
----
-Point = Struct.new :x, :y, keyword_init: true
+Point = Struct.new :x, :y
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
points.maximum(:x) # 2
points.maximum(:y) # 3
----
@@ -242,11 +246,11 @@
Answers the minimum extracted value from a collection of objects.
[source,ruby]
----
-Point = Struct.new :x, :y, keyword_init: true
+Point = Struct.new :x, :y
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
points.minimum(:x) # 0
points.minimum(:y) # 1
----
@@ -365,32 +369,36 @@
example[:b] # []
----
===== #compress
-Removes `nil` and empty objects without mutating itself.
+Removes `nil` and empty objects without mutating itself. Answers itself if there is nothing to remove.
[source,ruby]
----
object = Object.new
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
-example.compress # {a: 1, b: "blueberry", g: object}
-example # {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
+{}.compress # {}
+{a: 1, b: 2}.compress # {a: 1, b: 2}
+example.compress # {a: 1, b: "blueberry", g: object}
+example # {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
----
===== #compress!
-Removes `nil` and empty objects while mutating itself.
+Removes `nil` and empty objects while mutating itself. Answers `nil` if there is nothing to remove.
[source,ruby]
----
object = Object.new
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
-example.compress! # {a: 1, b: "blueberry", g: object}
-example # {a: 1, b: "blueberry", g: object}
+{}.compress! # nil
+{a: 1, b: 2}.compress! # nil
+example.compress! # {a: 1, b: "blueberry", g: object}
+example # {a: 1, b: "blueberry", g: object}
----
===== #deep_merge
Merges deeply nested hashes together without mutating itself.
@@ -483,13 +491,10 @@
[source,ruby]
----
{a: {b: 1}}.flatten_keys prefix: :test # {test_a_b: 1}
{a: {b: 1}}.flatten_keys delimiter: :| # {:"a|b" => 1}
-{a: {b: 1}}.flatten_keys cast: :to_s # {"a_b" => 1}
-{"a" => {"b" => 1}}.flatten_keys cast: :to_sym # {a_b: 1}
-
example = {a: {b: 1}}
example.flatten_keys # {a_b: 1}
example # {a: {b: 1}}
----
@@ -498,10 +503,13 @@
Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays,
though.
[source,ruby]
----
+{a: {b: 1}}.flatten_keys! prefix: :test # {test_a_b: 1}
+{a: {b: 1}}.flatten_keys! delimiter: :| # {:"a|b" => 1}
+
example = {a: {b: 1}}
example.flatten_keys! # {a_b: 1}
example # {a_b: 1}
----
@@ -595,18 +603,10 @@
----
example.transform_with bogus: -> value { value.tr "<>", "" }
# {email: "<jd@example.com>"}
----
-Nil values are skipped:
-
-[source,ruby]
-----
-{email: nil}.transform_with email: -> value { value.tr "<>", "" }
-# {email: nil}
-----
-
The original object will not be mutated:
[source,ruby]
----
example # {name: "Jayne Doe", email: "<jd@example.com>"}
@@ -633,18 +633,10 @@
----
example.transform_with! bogus: -> value { value.tr "<>", "" }
# {email: "<jd@example.com>"}
----
-Nil values are skipped:
-
-[source,ruby]
-----
-{email: nil}.transform_with! email: -> value { value.tr "<>", "" }
-# {email: nil}
-----
-
The original object will be mutated:
[source,ruby]
----
example # {name: "Jayne", email: "jd@example.com"}
@@ -1270,39 +1262,9 @@
io.reread(buffer: buffer) # "This is a test."
buffer # "This is a test."
----
==== Struct
-
-===== .keyworded?
-
-⚠️ Will be removed in the next major version. Use `.keyword_init?` instead.
-
-Answers whether a struct was constructed with keyword or positional arguments.
-
-[source,ruby]
-----
-Struct.new(:a, keyword_init: true).keyworded? # true
-Struct.new(:a).keyworded? # false
-----
-
-===== .with_keywords
-
-Answers a struct instance with given keyword arguments regardless of
-whether the struct was constructed with positional or keyword arguments.
-
-[source,ruby]
-----
-Example = Struct.new :a, :b, :c
-Example.with_keywords a: 1, b: 2, c: 3 # #<struct a=1, b=2, c=3>
-Example.with_keywords a: 1 # #<struct a=1, b=nil, c=nil>
-Example.with_keywords c: 1 # #<struct a=nil, b=nil, c=1>
-
-Example = Struct.new :a, :b, :c, keyword_init: true
-Example.with_keywords a: 1, b: 2, c: 3 # #<struct a=1, b=2, c=3>
-Example.with_keywords a: 1 # #<struct a=1, b=nil, c=nil>
-Example.with_keywords c: 1 # #<struct a=nil, b=nil, c=1>
-----
===== .with_positions
Answers a struct instance with given positional arguments regardless of
whether the struct was constructed with positional or keyword arguments.