From: "Hal E. Fulton" Date: 2003-02-27T05:39:44+09:00 Subject: Re: Coding challenge: Space-separated constants ----- Original Message ----- From: "Joel VanderWerf" To: "ruby-talk ML" Sent: Monday, February 24, 2003 1:17 AM Subject: Re: Coding challenge: Space-separated constants > Inefficient, but it seems to work... [snip Joel's code] I based this on Joel Vanderwerf's idea and made the following adjustments. 1. I divide the whole string into "pieces" that are each either whitespace or "blackspace" :) 2. I work a piece at a time instead of a char at a time I'll bet this is faster, though I haven't tried a speed comparison. I also added detection of malformed constants. Code below. Improvement/critique welcome. Hal class String def values pieces = self.scan(/[ \t]+|[^ \t]+/) vals = [] str = "" while pieces[0] do piece = pieces.shift str << piece if str =~ /^[ \t]+$/ # whitespace only str = "" next end begin vals << eval(str) str = "" rescue Exception if pieces[0] next else raise "Bad value near #{str}" end end end vals end end line1 = <