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 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 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