From: Vincent Isambart Date: 2007-08-25T17:22:32+09:00 Subject: String#length not working properly in Ruby 1.9 I saw that Matz just merged his M17N implementation in the trunk. However, the length method of String does not work as it should: # -*- coding: utf-8 -*- a = 'あ' p a.encoding p a.length p a.__send__(:length) displays: "UTF-8" 3 1 String#size does work fine. The problem comes from the fact that the VM has a length instruction that has its own implementation of the String length. A quick fix was to remove it as does the patch below. An other way to fix would be to reimplement it correctly using the encoding aware methods. Index: insns.def =================================================================== --- insns.def (revision 13268) +++ insns.def (working copy) @@ -1954,9 +1954,6 @@ if (HEAP_CLASS_OF(recv) == rb_cArray) { val = LONG2NUM(RARRAY_LEN(recv)); } - else if (HEAP_CLASS_OF(recv) == rb_cString) { - val = LONG2NUM(RSTRING_LEN(recv)); - } else if (HEAP_CLASS_OF(recv) == rb_cHash) { val = INT2FIX(RHASH(recv)->tbl->num_entries); }