----- Original Message ----- From: "Joel VanderWerf" <vjoel / PATH.Berkeley.EDU> To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Monday, February 24, 2003 1:17 AM Subject: Re: Coding challenge: Space-separated constants > Inefficient, but it seems to work... > > result = [] > until str.empty? > n = 1 > > loop do > begin > eval str[0...n] > rescue Exception > else > break if str[n,1] == " " or n == str.length > end > n += 1 > end > > result << eval(str.slice!(0...n)) > end > > p result > > You could tighten it up a bit by not eval-ing unless the substring is > followed by a space or the end of the string. Inefficient as you say, but very clever. A good example of something I would not have thought of. :) Hal