@shugoShugo Maeda なるほどなるほど。Encoding::UTF_16BEやEncoding::UTF_16LEでencodeした場合にはsizeは3になるようです。UTF-16でサロゲートペアになる文字を簡単に知ることができて便利だったのですが、他の方法を探しますw
@zundanzunda Ruby 3.1以前だと"吉村家".encode("UTF-16").sizeも4になるので𠮷を2と数えているのではなくてBOMも数えているのかもしれません。コードユニット数を数えるのは.encode("UTF-16LE").bytesize / 2でよさそうな気がします
If you have a fediverse account, you can quote this note from your own instance. Search https://ruby.social/users/shugo/statuses/114175877380694754 on your instance and quote it. (Note that quoting is not supported in Mastodon.)