Open In App

Ruby | String grapheme_clusters Method

Last Updated : 12 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
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 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 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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads