lib/polyfill/v2_5/string.rb in polyfill-1.3.0 vs lib/polyfill/v2_5/string.rb in polyfill-1.4.0
- old
+ new
@@ -36,8 +36,28 @@
prefixes.any? do |prefix|
prefix.is_a?(Regexp) ? self[/\A#{prefix}/] : super(prefix)
end
end
+
+ def grapheme_clusters
+ return scan(/\X/, &::Proc.new) if block_given?
+
+ scan(/\X/)
+ end
+
+ def each_grapheme_cluster
+ unless block_given?
+ grapheme_clusters = scan(/\X/)
+
+ return ::Enumerator.new(grapheme_clusters.size) do |yielder|
+ grapheme_clusters.each do |grapheme_cluster|
+ yielder.yield(grapheme_cluster)
+ end
+ end
+ end
+
+ scan(/\X/, &::Proc.new)
+ end
end
end
end