Skip to content

Commit cd9b746

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#each_char
1 parent 41149a9 commit cd9b746

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

doc/string/each_char.rdoc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
Calls the given block with each successive character from +self+;
1+
With a block given, calls the block with each successive character from +self+;
22
returns +self+:
33

4-
'hello'.each_char {|char| print char, ' ' }
5-
print "\n"
6-
'тест'.each_char {|char| print char, ' ' }
7-
print "\n"
8-
'こんにちは'.each_char {|char| print char, ' ' }
9-
print "\n"
4+
a = []
5+
'hello'.each_char do |char|
6+
a.push(char)
7+
end
8+
a # => ["h", "e", "l", "l", "o"]
9+
a = []
10+
'тест'.each_char do |char|
11+
a.push(char)
12+
end
13+
a # => ["т", "е", "с", "т"]
14+
a = []
15+
'こんにちは'.each_char do |char|
16+
a.push(char)
17+
end
18+
a # => ["こ", "ん", "に", "ち", "は"]
1019

11-
Output:
20+
With no block given, returns an enumerator.
1221

13-
h e l l o
14-
т е с т
15-
こ ん に ち は
16-
17-
Returns an enumerator if no block is given.
22+
Related: see {Iterating}[rdoc-ref:String@Iterating].

string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9798,7 +9798,7 @@ rb_str_enumerate_chars(VALUE str, VALUE ary)
97989798

97999799
/*
98009800
* call-seq:
9801-
* each_char {|c| ... } -> self
9801+
* each_char {|char| ... } -> self
98029802
* each_char -> enumerator
98039803
*
98049804
* :include: doc/string/each_char.rdoc

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy