Ruby | String chars() Method
Last Updated :
17 Dec, 2019
chars is a String class method in Ruby which is used to return an array of characters in str.
Syntax: str.chars
Parameters: Here, str is the given string
Returns: An array of the characters.
Example 1:
puts "Ruby String" .chars()
puts "Methods" .chars()
|
Output:
R
u
b
y
S
t
r
i
n
g
M
e
t
h
o
d
s
Example 2:
puts "GFG" .chars()
puts "G4G" .chars()
|
Output:
G
F
G
G
4
G
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...