README.adoc in refinements-11.1.0 vs README.adoc in refinements-11.1.1

- old
+ new

@@ -185,13 +185,13 @@ Answers the first element which evaluates to true from a filtered collection. [source,ruby] ---- handlers = [ - ->(object) { object if object == :b }, + -> object { object if object == :b }, proc { false }, - ->(object) { object if object == :a } + -> object { object if object == :a } ] handlers.filter_find # Enumerator::Lazy handlers.filter_find { |handler| handler.call :a } # :a handlers.filter_find { |handler| handler.call :x } # nil @@ -207,11 +207,11 @@ [1, 2, 3].including 4, 5 # [1, 2, 3, 4, 5] ---- ===== #intersperse -Inserts additional elements or an array between all members of given array. +Inserts additional elements, or an array, between all members of given array. [source,ruby] ---- [1, 2, 3].intersperse :a # [1, :a, 2, :a, 3] [1, 2, 3].intersperse :a, :b # [1, :a, :b, 2, :a, :b, 3] @@ -235,15 +235,17 @@ Answers the maximum extracted value from a collection of objects. [source,ruby] ---- -Point = Struct.new :x, :y +Point = Data.define :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 +points.maximum :x # 2 +points.maximum :y # 3 +points.maximum :z # undefined method `z' for #<data Point x=1, y=2> (NoMethodError) +[].maximum :x # nil ---- ===== #mean Answers mean/average all elements within an array. @@ -260,15 +262,17 @@ Answers the minimum extracted value from a collection of objects. [source,ruby] ---- -Point = Struct.new :x, :y +Point = Data.define :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 +points.minimum :x # 0 +points.minimum :y # 1 +points.minimum :z # undefined method `z' for #<data Point x=1, y=2> (NoMethodError) +[].minimum :x # nil ---- ===== #pad Answers new array padded with given value up to a maximum size. Useful in situations where an array @@ -290,11 +294,11 @@ array = [{name: "a", label: "A"}, {name: "b", label: "B"}, {name: "c", label: "C"}] array.pick :name # "a" array.pick :name, :label # ["a", "A"] array.pick # nil -[].pick(:other) # nil +[].pick :other # nil ---- ===== #pluck Answers values of all elements that match given keys. @@ -313,14 +317,14 @@ Answers mutated array where an element -- at a specific index -- is replaced by single or multiple elements. [source,ruby] ---- -%i[a b c].replace_at(0, :x) # [:x, :b, :c] -%i[a b c].replace_at(1, :x) # [:a, :x, :c] -%i[a b c].replace_at(1, :x, :y) # [:a, :x, :y, :c] -%i[a b c].replace_at(-1, :x) # [:a, :b, :x] +%i[a b c].replace_at 0, :x # [:x, :b, :c] +%i[a b c].replace_at 1, :x # [:a, :x, :c] +%i[a b c].replace_at 1, :x, :y # [:a, :x, :y, :c] +%i[a b c].replace_at -1, :x # [:a, :b, :x] ---- ===== #ring Answers a circular array which can enumerate before, current, after elements. @@ -794,16 +798,16 @@ [source,ruby] ---- io = IO.new IO.sysopen(Pathname("demo.txt").to_s, "w+") io.write "This is a demo." -io.reread # "This is a demo." -io.reread 4 # "This" +io.reread # "This is a demo." +io.reread 4 # "This" buffer = "".dup -io.reread(buffer: buffer) # "This is a demo." -buffer # "This is a demo." +io.reread(buffer:) # "This is a demo." +buffer # "This is a demo." ---- ===== #squelch Temporarily ignores any reads/writes for code executed within a block. Answers itself without any @@ -827,21 +831,21 @@ [source,ruby] ---- # With File. device = Logger::LogDevice.new "test.log" device.write "Test." -device.reread # "Test." +device.reread # "Test." # With StringIO. device = Logger::LogDevice.new StringIO.new device.write "Test." -device.reread # "Test." +device.reread # "Test." # With STDOUT. device = Logger::LogDevice.new $stdout device.write "Test." -device.reread # "" +device.reread # "" ---- ==== Logger ===== #reread @@ -851,21 +855,21 @@ [source,ruby] ---- # With File. logger = Logger.new "test.log" logger.write "Test." -logger.reread # "Test." +logger.reread # "Test." # With StringIO. logger = Logger.new StringIO.new logger.write "Test." -logger.reread # "Test." +logger.reread # "Test." # With STDOUT. logger = Logger.new $stdout logger.write "Test." -logger.reread # "" +logger.reread # "" ---- ===== #any Allows you to log _any_ message which is identical in behavior and functionality to the `Logger#unknown` method only this requires less typing and better matches the terminology used by the `#unknown` method. @@ -889,11 +893,11 @@ you have an instance of `Pathname`, which behaves like a _Null Object_, that can be used to construct a valid path. [source,ruby] ---- -Pathname(nil) # Pathname("") +Pathname nil # Pathname("") ---- ===== .home Answers user home directory. @@ -1015,24 +1019,24 @@ Deletes a path prefix and answers new pathname. [source,ruby] ---- -Pathname("a/path/example-test.rb").delete_prefix("example-") # Pathname("a/path/test.rb") -Pathname("example-test.rb").delete_prefix("example-") # Pathname("test.rb") -Pathname("example-test.rb").delete_prefix("miss") # Pathname("example-test.rb") +Pathname("a/path/example-test.rb").delete_prefix "example-" # Pathname("a/path/test.rb") +Pathname("example-test.rb").delete_prefix "example-" # Pathname("test.rb") +Pathname("example-test.rb").delete_prefix "miss" # Pathname("example-test.rb") ---- ===== #delete_suffix Deletes a path suffix and answers new pathname. [source,ruby] ---- -Pathname("a/path/test-example.rb").delete_suffix("-example") # Pathname("a/path/test.rb") -Pathname("test-example.rb").delete_suffix("-example") # Pathname("test.rb") -Pathname("test-example.rb").delete_suffix("miss") # Pathname("test-example.rb") +Pathname("a/path/test-example.rb").delete_suffix "-example" # Pathname("a/path/test.rb") +Pathname("test-example.rb").delete_suffix "-example" # Pathname("test.rb") +Pathname("test-example.rb").delete_suffix "miss" # Pathname("test-example.rb") ---- ===== #directories Answers all directories or filtered directories for current path. @@ -1082,14 +1086,14 @@ Same behavior as `String#gsub` but answers a path with patterns replaced with desired substitutes. [source,ruby] ---- -Pathname("/a/path/some/path").gsub("path", "test") +Pathname("/a/path/some/path").gsub "path", "test" # Pathname("/a/test/some/test") -Pathname("/%placeholder%/some/%placeholder%").gsub("%placeholder%", "test") +Pathname("/%placeholder%/some/%placeholder%").gsub "%placeholder%", "test" # Pathname("/test/some/test") ---- ===== #make_ancestors @@ -1133,15 +1137,15 @@ Pathname("example.txt").name # Pathname("example") ---- ===== #relative_parent -Answers relative path from parent directory. This is a complement to `#relative_path_from`. +Answers relative path from parent directory. This complements: `#relative_path_from`. [source,ruby] ---- -Pathname("/one/two/three").relative_parent("/one") # Pathname "two" +Pathname("/one/two/three").relative_parent "/one" # Pathname "two" ---- ===== #remove_dir Provides alternative `#rmdir` behavior by always answering itself (even when full path exists) and @@ -1376,12 +1380,12 @@ io.reread # "This is a test." io.reread 4 # "This" buffer = "".dup -io.reread(buffer: buffer) # "This is a test." -buffer # "This is a test." +io.reread(buffer:) # "This is a test." +buffer # "This is a test." ---- ==== Struct ===== .with_positions @@ -1456,12 +1460,11 @@ ===== #revalue Transforms values without mutating itself. An optional hash can be supplied to target specific attributes. In the event that a block isn't supplied, the struct will answer itself since there is -nothing to operate on. Behavior is the same regardless of whether the struct is constructed using -positional or keyword arguments. Works regardless of whether the struct is constructed with +nothing to operate on. Works regardless of whether the struct is constructed with positional or keyword arguments. [source,ruby] ---- example = Struct.new("Example", :a, :b, :c).new 1, 2, 3 @@ -1475,11 +1478,10 @@ ===== #revalue! Transforms values while mutating itself. An optional hash can be supplied to target specific attributes. In the event that a block isn't supplied, the struct will answer itself since there is -nothing to operate on. Behavior is the same regardless of whether the struct is constructed using -positional or keyword arguments. Works regardless of whether the struct is constructed with +nothing to operate on. Works regardless of whether the struct is constructed with positional or keyword arguments. [source,ruby] ---- one = Struct.new("One", :a, :b, :c).new 1, 2, 3