From: Robert Klemme Date: 2004-04-27T17:29:02+09:00 Subject: Re: slice returning multiple values "Joel VanderWerf" schrieb im Newsbeitrag news:408D404D.3070801@path.berkeley.edu... > > Fantasy for the day... > > str = "foo bar" > x, y = str[/(foo) (bar)/, 1, 2] > > x # ==> "foo" > y # ==> "bar" > > Oh, well, there is always this: > > (x, y), = str.scan(/(foo) (bar)/) irb(main):007:0> x, y = str.match(/(foo) (bar)/).to_a[1..2] => ["foo", "bar"] irb(main):010:0> x, y = str.split /\s+/ => ["foo", "bar"] irb(main):011:0> x => "foo" irb(main):012:0> y => "bar" irb(main):013:0> irb(main):013:0> x, y = str.scan /\w+/ => ["foo", "bar"] irb(main):018:0> x, y, rest = str.split( /\s+/, 3 ) => ["foo", "bar"] irb(main):019:0> rest => nil robert