From 772072a99cbe43a09a262cf1475e6c0b0e4c5e53 Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Mon, 14 May 2018 20:37:07 +0200 Subject: [PATCH 1/2] Add other examples to String#% --- src/string.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/string.cr b/src/string.cr index 5868ae16fc2a..45b9b4773ebc 100644 --- a/src/string.cr +++ b/src/string.cr @@ -4054,7 +4054,9 @@ class String # Interpolates *other* into the string using `Kernel#sprintf`. # # ``` - # "Party like it's %d!!!" % 1999 # => "Party like it's 1999!!!" + # "I have %d apples" % 5 # => "I have 5 apples" + # "%s, %s, %s, D" % ['A', 'B', 'C'] # => "A, B, C, D" + # "sum: %{one} + %{two} = %{three}" % ({one: 1, two: 2, three: 1 + 2}) # => "sum: 1 + 2 = 3" # ``` def %(other) sprintf self, other From 2103784c72434f1c10e4e8a744b382063ea31479 Mon Sep 17 00:00:00 2001 From: r00ster <35064754+r00ster91@users.noreply.github.com> Date: Mon, 14 May 2018 21:20:57 +0200 Subject: [PATCH 2/2] Update string.cr --- src/string.cr | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/string.cr b/src/string.cr index 45b9b4773ebc..a1c7aaea8def 100644 --- a/src/string.cr +++ b/src/string.cr @@ -4054,9 +4054,10 @@ class String # Interpolates *other* into the string using `Kernel#sprintf`. # # ``` - # "I have %d apples" % 5 # => "I have 5 apples" - # "%s, %s, %s, D" % ['A', 'B', 'C'] # => "A, B, C, D" - # "sum: %{one} + %{two} = %{three}" % ({one: 1, two: 2, three: 1 + 2}) # => "sum: 1 + 2 = 3" + # "I have %d apples" % 5 # => "I have 5 apples" + # "%s, %s, %s, D" % ['A', 'B', 'C'] # => "A, B, C, D" + # "sum: %{one} + %{two} = %{three}" % {one: 1, two: 2, three: 1 + 2} # => "sum: 1 + 2 = 3" + # "I have %s apples" % {apples: 4} # => "I have 4 apples" # ``` def %(other) sprintf self, other