summaryrefslogtreecommitdiff
path: root/doc/string
diff options
context:
space:
mode:
authorBurdette Lamar <BurdetteLamar@Yahoo.com>2022-03-28 15:49:18 -0500
committerGitHub <noreply@github.com>2022-03-28 15:49:18 -0500
commit5525e47a0b5e6b6c3e13ceec4b44535feba22631 (patch)
treed0f32ad2957aa016ecbec69c895b8ae10d2a9e3a /doc/string
parent79bd12a6e4b5dfc44d522bb0ac55fda15d549740 (diff)
downloadruby-5525e47a0b5e6b6c3e13ceec4b44535feba22631.tar.gz
[DOC] Enhanced RDoc for String (#5726)
Treats: #ljust #rjust #center #partition #rpartition
Diffstat (limited to 'doc/string')
-rw-r--r--doc/string/center.rdoc16
-rw-r--r--doc/string/ljust.rdoc16
-rw-r--r--doc/string/partition.rdoc24
-rw-r--r--doc/string/rjust.rdoc16
-rw-r--r--doc/string/rpartition.rdoc24
-rw-r--r--doc/string/split.rdoc2
6 files changed, 98 insertions, 0 deletions
diff --git a/doc/string/center.rdoc b/doc/string/center.rdoc
new file mode 100644
index 0000000000..d53d921ad5
--- /dev/null
+++ b/doc/string/center.rdoc
@@ -0,0 +1,16 @@
+Returns a centered copy of +self+.
+
+If integer argument +size+ is greater than the size (in characters) of +self+,
+returns a new string of length +size+ that is a copy of +self+,
+centered and padded on both ends with +pad_string+:
+
+ 'hello'.center(10) # => " hello "
+ ' hello'.center(10) # => " hello "
+ 'hello'.center(10, 'ab') # => "abhelloaba"
+ 'тест'.center(10) # => " тест "
+ 'こんにちは'.center(10) # => " こんにちは "
+
+If +size+ is not greater than the size of +self+, returns a copy of +self+:
+
+ 'hello'.center(5) # => "hello"
+ 'hello'.center(1) # => "hello"
diff --git a/doc/string/ljust.rdoc b/doc/string/ljust.rdoc
new file mode 100644
index 0000000000..8e23c1fc8f
--- /dev/null
+++ b/doc/string/ljust.rdoc
@@ -0,0 +1,16 @@
+Returns a left-justified copy of +self+.
+
+If integer argument +size+ is greater than the size (in characters) of +self+,
+returns a new string of length +size+ that is a copy of +self+,
+left justified and padded on the right with +pad_string+:
+
+ 'hello'.ljust(10) # => "hello "
+ ' hello'.ljust(10) # => " hello "
+ 'hello'.ljust(10, 'ab') # => "helloababa"
+ 'тест'.ljust(10) # => "тест "
+ 'こんにちは'.ljust(10) # => "こんにちは "
+
+If +size+ is not greater than the size of +self+, returns a copy of +self+:
+
+ 'hello'.ljust(5) # => "hello"
+ 'hello'.ljust(1) # => "hello"
diff --git a/doc/string/partition.rdoc b/doc/string/partition.rdoc
new file mode 100644
index 0000000000..ebe575e8eb
--- /dev/null
+++ b/doc/string/partition.rdoc
@@ -0,0 +1,24 @@
+Returns a 3-element array of substrings of +self+.
+
+Matches a pattern against +self+, scanning from the beginning.
+The pattern is:
+
+- +string_or_regexp+ itself, if it is a Regexp.
+- <tt>Regexp.quote(string_or_regexp)</tt>, if +string_or_regexp+ is a string.
+
+If the pattern is matched, returns pre-match, first-match, post-match:
+
+ 'hello'.partition('l') # => ["he", "l", "lo"]
+ 'hello'.partition('ll') # => ["he", "ll", "o"]
+ 'hello'.partition('h') # => ["", "h", "ello"]
+ 'hello'.partition('o') # => ["hell", "o", ""]
+ 'hello'.partition(/l+/) #=> ["he", "ll", "o"]
+ 'hello'.partition('') # => ["", "", "hello"]
+ 'тест'.partition('т') # => ["", "т", "ест"]
+ 'こんにちは'.partition('に') # => ["こん", "に", "ちは"]
+
+If the pattern is not matched, returns a copy of +self+ and two empty strings:
+
+ 'hello'.partition('x') # => ["hello", "", ""]
+
+Related: String#rpartition, String#split.
diff --git a/doc/string/rjust.rdoc b/doc/string/rjust.rdoc
new file mode 100644
index 0000000000..24e7bf3159
--- /dev/null
+++ b/doc/string/rjust.rdoc
@@ -0,0 +1,16 @@
+Returns a right-justified copy of +self+.
+
+If integer argument +size+ is greater than the size (in characters) of +self+,
+returns a new string of length +size+ that is a copy of +self+,
+right justified and padded on the left with +pad_string+:
+
+ 'hello'.rjust(10) # => " hello"
+ 'hello '.rjust(10) # => " hello "
+ 'hello'.rjust(10, 'ab') # => "ababahello"
+ 'тест'.rjust(10) # => " тест"
+ 'こんにちは'.rjust(10) # => " こんにちは"
+
+If +size+ is not greater than the size of +self+, returns a copy of +self+:
+
+ 'hello'.rjust(5, 'ab') # => "hello"
+ 'hello'.rjust(1, 'ab') # => "hello"
diff --git a/doc/string/rpartition.rdoc b/doc/string/rpartition.rdoc
new file mode 100644
index 0000000000..d24106fb9f
--- /dev/null
+++ b/doc/string/rpartition.rdoc
@@ -0,0 +1,24 @@
+Returns a 3-element array of substrings of +self+.
+
+Matches a pattern against +self+, scanning backwards from the end.
+The pattern is:
+
+- +string_or_regexp+ itself, if it is a Regexp.
+- <tt>Regexp.quote(string_or_regexp)</tt>, if +string_or_regexp+ is a string.
+
+If the pattern is matched, returns pre-match, last-match, post-match:
+
+ 'hello'.rpartition('l') # => ["hel", "l", "o"]
+ 'hello'.rpartition('ll') # => ["he", "ll", "o"]
+ 'hello'.rpartition('h') # => ["", "h", "ello"]
+ 'hello'.rpartition('o') # => ["hell", "o", ""]
+ 'hello'.rpartition(/l+/) # => ["hel", "l", "o"]
+ 'hello'.rpartition('') # => ["hello", "", ""]
+ 'тест'.rpartition('т') # => ["тес", "т", ""]
+ 'こんにちは'.rpartition('に') # => ["こん", "に", "ちは"]
+
+If the pattern is not matched, returns two empty strings and a copy of +self+:
+
+ 'hello'.rpartition('x') # => ["", "", "hello"]
+
+Related: String#partition, String#split.
diff --git a/doc/string/split.rdoc b/doc/string/split.rdoc
index d93b76d9b4..2b5e14ddb6 100644
--- a/doc/string/split.rdoc
+++ b/doc/string/split.rdoc
@@ -82,3 +82,5 @@ Output:
"abc"
"def"
"ghi"
+
+Related: String#partition, String#rpartition.