Ruby | String each_grapheme_cluster Method
Last Updated :
12 Dec, 2019
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:
puts "Ruby" .each_grapheme_cluster
puts "String" .each_grapheme_cluster.to_a.size
|
Output:
#
6
Example 2:
puts "Sample" .each_grapheme_cluster
puts "Input" .each_grapheme_cluster.to_a.size
|
Output:
#
5
Share your thoughts in the comments
Please Login to comment...