From: Dave Oshel Date: 2003-05-23T08:44:16+09:00 Subject: Re: why is "does" missing from this sub!-stitution? In article <20030522202818.GA24497@student.ei.uni-stuttgart.de>, Mauricio Fern�ndez wrote: > On Fri, May 23, 2003 at 05:23:47AM +0900, Dave Oshel wrote: > > [~/Desktop] dave$ cat foobar.rb ; foobar.rb > > #!/usr/local/bin/ruby > > > > # get a Stanislaw Lem quote containing underscores and backspaces, then > > # replace the word following the deleted underscores and backspaces > > # with the same word surrounded by emphatic arrow glyphs > > > > `fortune -m Nillity`.each do |x| > > x.sub!( /(_+\010+)([a-zA-Z]+)/, "-->#{$2}<--" ) > > print x > > end > > The second argument is evaluated only once (think about it), on method > call, when $2 == nil. > > use > x.sub!( /(_+\010+)([a-zA-Z]+)/ ) { "-->#{$2}<--" } Maybe so, but this works as expected: `/sw/bin/fortune -m Nillity`.each { |x| x.sub!( /(_+\010+)([a-zA-Z]+\b)/, "" + '\2' + "" ) print x } Maybe it's a bug ... or a feature ... or a bug ... or a bug AND a feature ... ;-) -- ["10110100101101000101000000100010100001100110111010010110001001100000010011000010011101000000010011110010110011100001011010100110001101101001000010010000001001101100011011110110110011100001011010100110001101100000001010110110100001101100011001110100110001101111011010110110010100001100001010100110001001101000011001001110000001000100101010000110000011101001011000100110110011100011010000000100100100101000001010010000000101100010111000101110000011100101110011110100111101000001011011110110101101101010011000001110100001101110011010100110011101001011011010000110110001100111010011000110111101101011011011110100001001101100011011110110110011100001011010100110001101101111010001010000010001001001101010100110001011100000010010000010011101101111011000101110000101101010011001001110000001000100101010101110010001101001111000000100000100101000011011000110110101101010011001001110"].pack("b*")