Open In App
Related Articles

Ruby | String chars() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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:
# Ruby program to demonstrate 
# the chars method 
       
# Taking a string and 
# using the method 
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:
# Ruby program to demonstrate 
# the chars method 
       
# Taking a string and 
# using the method 
puts "GFG".chars() 
puts "G4G".chars() 

                    
Output:
G
F
G
G
4
G

Last Updated : 17 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads