README.adoc in refinements-11.1.3 vs README.adoc in refinements-12.0.0

- old
+ new

@@ -11,21 +11,20 @@ == Features Enhances the following objects: * Array -* BigDecimal * Data * DateTime * Hash * IO * LogDevice * Logger * Pathname * String * StringIO -* Structs +* Struct == Requirements . https://www.ruby-lang.org[Ruby]. . A solid understanding of link:https://alchemists.io/articles/ruby_refinements[refinements]. @@ -75,46 +74,44 @@ ...then require the specific refinement, as needed. Example: [source,ruby] ---- -require "refinements/arrays" -require "refinements/big_decimals" +require "refinements/array" require "refinements/data" -require "refinements/date_times" -require "refinements/hashes" -require "refinements/ios" -require "refinements/pathnames" -require "refinements/strings" -require "refinements/string_ios" -require "refinements/structs" -require "refinements/symbols" -require "refinements/log_devices" -require "refinements/loggers" +require "refinements/date_time" +require "refinements/hash" +require "refinements/io" +require "refinements/log_device" +require "refinements/logger" +require "refinements/pathname" +require "refinements/string" +require "refinements/string_io" +require "refinements/struct" +require "refinements/symbol" ---- === Using Much like including/extending a module, you’ll need to modify your object(s) to use the refinement(s): [source,ruby] ---- class Example - using Refinements::Arrays - using Refinements::BigDecimals + using Refinements::Array using Refinements::Data - using Refinements::DateTimes - using Refinements::Hashes - using Refinements::IOs - using Refinements::Pathnames - using Refinements::Strings - using Refinements::StringIOs - using Refinements::Structs - using Refinements::Symbols - using Refinements::LogDevices - using Refinements::Loggers + using Refinements::DateTime + using Refinements::Hash + using Refinements::IO + using Refinements::LogDevice + using Refinements::Logger + using Refinements::Pathname + using Refinements::String + using Refinements::StringIO + using Refinements::Struct + using Refinements::Symbol end ---- === Examples @@ -278,13 +275,13 @@ Answers new array padded with given value up to a maximum size. Useful in situations where an array needs to be a specific size with padded values. [source,ruby] ---- -[1].pad 0 # [1] -[1].pad 0, max: 3 # [1, 0, 0] -[1, 2].pad 3, max: 3 # [1, 2, 3] +["a"].pad 0 # ["a"] +["a"].pad "-", 3 # ["a", "-", "-"] +%w[a b].pad "-", 3 # ["a", "b", "-"] ---- ===== #pick Answers value of first element that matches given key. @@ -391,21 +388,10 @@ [1, "a", :b, 2.0, /\w+/].to_usage # "1, \"a\", :b, 2.0, and /\\w+/" %w[one two three].to_usage # "\"one\", \"two\", and \"three\"" %w[eins zwei drei].to_usage "und", delimiter: " " # "\"eins\" \"zwei\" und \"drei\"" ---- -==== Big Decimal - -===== #inspect - -Allows one to inspect a big decimal with numeric representation. - -[source,ruby] ----- -BigDecimal.new("5.0E-10").inspect # "#<BigDecimal:3fd3d458fe84 0.0000000005>" ----- - ==== Data ===== #diff Allows you to obtain the differences between two objects. @@ -1286,15 +1272,15 @@ well in other languages. [source,ruby] ---- "apple".pluralize "s" # apples -"apple".pluralize "s", count: 0 # apples -"apple".pluralize "s", count: 1 # apple -"apple".pluralize "s", count: -1 # apple -"apple".pluralize "s", count: 2 # apples -"apple".pluralize "s", count: -2 # apples +"apple".pluralize "s", 0 # apples +"apple".pluralize "s", 1 # apple +"apple".pluralize "s", -1 # apple +"apple".pluralize "s", 2 # apples +"apple".pluralize "s", -2 # apples "cactus".pluralize "i", replace: "us" # cacti "cul-de-sac".pluralize "ls", replace: "l" # culs-de-sac ---- ===== #singularize @@ -1306,15 +1292,15 @@ well in other languages. [source,ruby] ---- "apples".singularize "s" # apple -"apples".singularize "s", count: 0 # apples -"apples".singularize "s", count: 1 # apple -"apples".singularize "s", count: -1 # apple -"apples".singularize "s", count: 2 # apples -"apples".singularize "s", count: -2 # apples +"apples".singularize "s", 0 # apples +"apples".singularize "s", 1 # apple +"apples".singularize "s", -1 # apple +"apples".singularize "s", 2 # apples +"apples".singularize "s", -2 # apples "cacti".singularize "i", replace: "us" # cactus "culs-de-sac".singularize "ls", replace: "l" # cul-de-sac ---- ===== #snakecase @@ -1343,10 +1329,34 @@ [source,ruby] ---- "ThisIsAnExample".titleize # "This Is An Example" ---- +===== #truncate + +Answers a truncated, non-mutated, string for given length with optional delimiter and/or overflow. + +The delimiter is the second positional parameter (optional) and is `nil` by default. A custom string or regular expression can be used to customize truncation behavior. + +The trailer is an optional keyword parameter that is an ellipsis (i.e. `"..."`) by default. The trailer can be a custom or empty string. The string length of the trailer is added to the length of the string being truncated, so keep this in mind when setting truncation length. + +[source,ruby] +---- +demo = "It was the best of times" +length = demo.length + +demo.truncate 9 # "It was..." +demo.truncate 12 # "It was th..." +demo.truncate length # "It was the best of times" +demo.truncate Float::INFINITY # "It was the best of times" +demo.truncate 12, " " # "It was..." +demo.truncate 12, /\s/ # "It was..." +demo.truncate 6, trailer: "" # "It was" +demo.truncate 16, trailer: "... (more)" # "It was... (more)" +"demo".truncate 3 # "..." +---- + ===== #to_bool Answers string as a boolean. [source,ruby] @@ -1549,10 +1559,10 @@ %w[1.outside 2.inside].map(&:sub.call(/\./) { |bullet| bullet + " " }) # ["1. outside", "2. inside"] [1, 2, 3].map(&:to_s.call) # ["1", "2", "3"] ---- ⚠️ Use of `#call` without any arguments or block should be avoided in order to not incur extra -processing costs since the original symbol-to-proc call can used instead. +processing costs since the original symbol-to-proc call can be used instead. == Development To contribute, run: