Ruby | String each_grapheme_cluster Method
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
Last Updated :
12 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...