From: "Mauricio Fernández" Date: 2003-05-23T05:28:22+09:00 Subject: Re: why is "does" missing from this sub!-stitution? 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}<--" } -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com *** PUBLIC flooding detected from erikyyy THAT's an erik, pholx.... ;) -- Seen on #LinuxGER