From: Alex Young Date: 2007-05-27T17:17:11+09:00 Subject: Re: Strange behavior of String.scan H奪vard Moen wrote: > When I use String.scan with a block and just one group the result ends > up as an array. More than one group works as expected. A small example to > demonstrate: > > --ruby code start-- > data = ' lb method member observed > monitor all http > member 192.168.1.68:http' > data.scan(/monitor all (.*)$/) do |monitor| > puts monitor.inspect > end > data.scan(/member ([0-9.]+):(.*)/) do |adress, port| > puts adress.inspect > puts port.inspect > end > --ruby code end-- > > gives me: > ["http"] > "192.168.1.68" > "http" That's expected. What scan actually yields to the block is an array, and in your second example that array is being automatically split into its component parts because you've given more than one block parameter in the pipes. A third example should make it clear: irb(main):004:0> data.scan(/member ([0-9.]+):(.*)/) do |match| irb(main):005:1* puts match.inspect irb(main):006:1> end ["192.168.1.68", "http"] -- Alex