Open In App

Ruby | String each_grapheme_cluster Method

Last Updated : 12 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
each_grapheme_cluster is a String class method in Ruby which is used to pass each grapheme cluster in the given string to the given block, or returns an enumerator if no block is given.
Syntax: str.each_grapheme_cluster Parameters: Here, str is the given string. Returns: An enumerator.
Example 1: Ruby
# Ruby program to demonstrate 
# the each_grapheme_cluster method 
     
# Taking a string and 
# using the method
puts "Ruby".each_grapheme_cluster
puts "String".each_grapheme_cluster.to_a.size
Output:
#
6
Example 2: Ruby
# Ruby program to demonstrate 
# the each_grapheme_cluster method 
     
# Taking a string and 
# using the method
puts "Sample".each_grapheme_cluster
puts "Input".each_grapheme_cluster.to_a.size
Output:
#
5

Next Article

Similar Reads