From: Charles Mills Date: 2005-09-24T05:21:40+09:00 Subject: Re: to_str in string.c # rb_str_to_str() Timothy Byrd wrote: > I have a Bignum object and I tried calling StringValueCStr() to get it > in string form. This raises: > > (eval): cannot convert Bignum into String (TypeError) > > I believe this is ultimately because this routine in string.c is being > called: > > VALUE > rb_str_to_str(str) > VALUE str; > { > return rb_convert_type(str, T_STRING, "String", "to_str"); > } > > Why is to_str used here? Should it be to_s, since only a few classes > seem to have to_str? > > -- Timothy No, it should be to_str. All objects implement to_s since all classes are decendents of Object which implements to_s. to_str is reserved for objects that behave like a string. So if you implemented your own special string class (take your pick http://www.and.org/vstr/comparison.html) then you should implement to_str (and to_str should convert an instance of your string class into a Ruby String object). Use rb_String(num) or rb_big2str(num, 10). -Charlie