Ruby 3.3 リファレンスマニュアル

instance method String#bytesize

bytesize -> Integer[permalink][rdoc][edit]

文字列のバイト長を整数で返します。

#coding:UTF-8
# 実行結果は文字コードによって異なります。
p "いろは".size     # => 3
p "いろは".bytesize # => 9

[SEE_ALSO] String#size