Skip to content
Related Articles

Related Articles

Improve Article

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:






# 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
My Personal Notes arrow_drop_up
Recommended Articles
Page :