Open In App

Ruby | String chars() Method

Last Updated : 17 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
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
# 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
# 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

Next Article

Similar Reads