a = [[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]
puts '{{' + a.map{|b| b.join(', ')}.join('}, {') + '}}'
=>{{1.4, 2.2, 2.1, 4.2}, {2.1, 3.1, 2.4, 2.2}, {3.1, 1.3, 2.5, 2.1}}
cheers
Simon
···
-----Original Message-----
From: pete boardman [mailto:pete.boardman@pobox.com]
Sent: Tuesday, October 11, 2005 2:27 PM
To: ruby-talk ML
Subject: Re: Sort pseudo-listsOne more thing - I forgot that I need to get the result back to a
string... So (thanks to your help andn Ruby's 'eval') I can go from
this:"{{3.1, 1.3, 2.5, 2.1}, {2.1, 3.1, 2.4, 2.2}, {1.4, 2.2, 2.1, 4.2}}"
to this:
[[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]
but I can't persuade the 'p' method to turn this back into a string:
"[[1.4, 2.2, 2.1, 4.2], [2.1, 3.1, 2.4, 2.2], [3.1, 1.3, 2.5, 2.1]]"
(and I should be able to go from here to :
"{{1.4, 2.2, 2.1, 4.2}, {2.1, 3.1, 2.4, 2.2}, {3.1, 1.3, 2.5, 2.1}}"
on my own
Pete