From: Todd Benson Date: 2007-12-30T19:14:03+09:00 Subject: Re: sub is odd with # On Dec 30, 2007 4:10 AM, Todd Benson wrote: > On Dec 30, 2007 3:11 AM, Pavel Pvl wrote: > > seems to me as though I'm redundant on this forum... > > > > > > well anyway, doing '@@@@'.sub('@','#') > > > > returns > > '/#@@@' > > It should return "\#@@@" (backslash before a character inside a double > quoted string is an escaped character). You are looking at the > general string representation of '#@@@'. Do this to see what I mean > ... > > irb> '@@@@'.sub('@', '#').each_byte { |b| puts b } > > When you use 1.8 you see 4 integers, the first one the byte code for > the # sign, the others for the @ sign. I think 1.9 is the same way > with #each_byte, but haven't tried it out. > > > > > how can I make it so that it doesn't through in the / ? > > irb> puts '@@@@'.sub('@', '#') > > > > > using 1.9 btw > > > > gsub doesn't do that, but I specifically ned sub to do that. > > '####' is not special and doesn't need to be escaped. > > The character sequence '#@' is because it is a short hand way of > "exploding" a class variable inside a String. That would be "class instance variable". My bad. Todd