Bug in String.index?

Hi!
Is this a bug or a strange feature?

a = ""
a << 240
puts a[0]
puts a.index(240)

gives:
240
nil

ruby --version:
ruby 1.7.3 (2002-12-16) [i686-linux]
(1.8.1 shows the same behaviour)

Thanks for any workaround in advance
Martin.

Martin Kahlert wrote:

Is this a bug or a strange feature?

No idea.

Thanks for any workaround in advance

It seems like

a.index( 240.chr )

works as expected.

(ruby 1.8.0 (2003-08-04) [i586-linux-gnu])

···


([ Kent Dahl ]/)_ ~ [ Kent Dahl - Kent Dahl ]/~
))_student_/(( _d L b_/ Master of Science in Technology )
( __õ|õ// ) ) Industrial economics and technology management (
_
/ö____/ (_engineering.discipline=Computer::Technology)

Hi,

At Fri, 16 Apr 2004 19:54:15 +0900,
Martin Kahlert wrote in [ruby-talk:97342]:

Is this a bug or a strange feature?

A bug.

Index: string.c

···

===================================================================
RCS file: /cvs/ruby/src/ruby/string.c,v
retrieving revision 1.190
diff -u -2 -p -r1.190 string.c
— string.c 14 Apr 2004 04:06:25 -0000 1.190
+++ string.c 16 Apr 2004 11:25:30 -0000
@@ -1079,5 +1079,5 @@ rb_str_index_m(argc, argv, str)
case T_FIXNUM:
{

  • int c = FIX2INT(sub);
    
  • char c = (char)FIX2INT(sub);
    long len = RSTRING(str)->len;
    char *p = RSTRING(str)->ptr;
    

@@ -1202,5 +1202,5 @@ rb_str_rindex_m(argc, argv, str)
case T_FIXNUM:
{

  • int c = FIX2INT(sub);
    
  • char c = (char)FIX2INT(sub);
    char *p = RSTRING(str)->ptr + pos;
    char *pbeg = RSTRING(str)->ptr;
    


Nobu Nakada

Hi,

···

In message “Re: Bug in String.index?” on 04/04/16, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

At Fri, 16 Apr 2004 19:54:15 +0900,
Martin Kahlert wrote in [ruby-talk:97342]:

Is this a bug or a strange feature?

A bug.

Indeed. I will fix.

						matz.

Hi,

In article 1082564201.620493.6072.nullmailer@picachu.netlab.jp,
matz@ruby-lang.org (Yukihiro Matsumoto) writes:

Hi,

At Fri, 16 Apr 2004 19:54:15 +0900,
Martin Kahlert wrote in [ruby-talk:97342]:

Is this a bug or a strange feature?

A bug.

Indeed. I will fix.

  					matz.

Thanks a lot for all replies - especially for nobu.nokada’s patch!
Will this patch be included into the stable series?
In my today’s snapshot it does not work out of the box and the patch seems
not to be in, yet.

Regards
Martin.

···

In message “Re: Bug in String.index?” > on 04/04/16, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

Hi,

···

In message “Re: Bug in String.index?” on 04/04/28, Martin Kahlert mkcon@gmx.net writes:

Thanks a lot for all replies - especially for nobu.nokada’s patch!
Will this patch be included into the stable series?
In my today’s snapshot it does not work out of the box and the patch seems
not to be in, yet.

I’m working on local copy. Wait for a few days.

						matz.