From: El Gato Date: 2006-11-21T11:35:01+09:00 Subject: Re: How to put array into variables El Gato wrote: > Ken Allen wrote: >> This also works: >> b = "word1 word2" >> ((a,b)) = b.scan(/^(\w+)\s(\w+)$/) >> p a => "word1" >> p b => "word2" >> >> The outer parens matches the outer array, and the inner parens matches >> the inner array, allowing a and b to decompose it. >> It's a pretty useful trick when decomposing nested arrays. >> >> Ken > > Seems like the long way around... > > foo = ["one", "two"] > a, b = foo > a #=> "one" > b #=> "two" Actually, to be more clear foo = "hello world" a,b = foo.split a #=> "hello" b #=> "world" -- Posted via http://www.ruby-forum.com/.