2009/2/19 Joel VanderWerf <vjoel / path.berkeley.edu>:
>
> We have this:
>
> a = %w{ a b c d e f }
> p a # ==> ["a", "b", "c", "d", "e", "f"]
>
> Has anyone ever felt the need for something like
>
> a = %t{
>  a b c
>  d e f
> } # ==> [["a", "b", "c"], ["d", "e", "f"]]
>
> It's probably too special (this is the first time in 8 years I've wanted
> it), and it is easy to implement it as a method rather than a literal:
>
> def table s
>  s.split("\n").map!{|t|t.split}
> end
>
> t = table %q{\
>  a b c
>  d e f
> }
>
> p t  # ==> [["a", "b", "c"], ["d", "e", "f"]]
>
> Really just an idle question...

You can also exploit the line iteration capabilities of String, which
is especially easy in 1.8.x

09:20:42 ddl$ irb19
Ruby version 1.9.1
irb(main):001:0> s = <<EOF
irb(main):002:0" a b c
irb(main):003:0" 1 2 3
irb(main):004:0" r t z
irb(main):005:0" EOF
=> "a b c\n1 2 3\nr t z\n"
irb(main):006:0> s.each_line.map {|x| x.scan /\S+/}
=> [["a", "b", "c"], ["1", "2", "3"], ["r", "t", "z"]]
irb(main):007:0> exit
09:21:14 ddl$ irb
Ruby version 1.8.7
irb(main):001:0> s = <<EOF
irb(main):002:0" a b c
irb(main):003:0" 1 2 3
irb(main):004:0" r t z
irb(main):005:0" EOF
=> "a b c\n1 2 3\nr t z\n"
irb(main):006:0> s.map {|x| x.scan /\S+/}
=> [["a", "b", "c"], ["1", "2", "3"], ["r", "t", "z"]]
irb(main):007:0> exit
09:21:48 ddl$

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end