Open In App

Ruby | String grapheme_clusters Method

Last Updated : 12 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
grapheme_clusters is a String class method in Ruby which is used to return an array of grapheme clusters in the given string.
Syntax: str.grapheme_clusters Parameters: Here, str is the given string. Returns: An array of grapheme clusters.
Example 1: Ruby
# Ruby program to demonstrate 
# the grapheme_clusters method 
     
# Taking a string and 
# using the method
puts "Sample".grapheme_clusters

puts "Program".grapheme_clusters
Output:
S
a
m
p
l
e
P
r
o
g
r
a
m
Example 2: Ruby
# Ruby program to demonstrate 
# the grapheme_clusters method 
     
# Taking a string and 
# using the method
puts "Ruby\n".grapheme_clusters

puts "String".grapheme_clusters
Output:
R
u
b
y

S
t
r
i
n
g

Next Article

Similar Reads