From: James Edward Gray II Date: 2005-08-26T06:41:23+09:00 Subject: Re: [SUMMARY] Sodoku Solver (#43) On Aug 25, 2005, at 4:10 PM, Adam Shelly wrote: > On 8/25/05, Ruby Quiz wrote: > >> I believe Adam Shelly's parse routine could benefit from similar >> simplifications >> if you want to try your own hand at a little refactoring. >> > > Ok, I admit I'm a ruby newbie. But I'm trying to learn the Ruby Way. > How's this? No worries there! [snip old code] > def ParseBoard(file) > boardlist,size = [ ],0 > file.each do |line| > if line.delete!('^0-9A-Za-z_+') =~ /\++/ Beware the bang methods (ending in !) in Ruby. Obviously it's fine to use them, but it's almost never a good idea to chain them. Most of them return nil when they don't make a change and nil doesn't support very many calls, like the =~ operator you use here. Feed it the wrong line and the code will crash. In this case, you should be able to just drop the !, as delete() returns a copy of the String when nothing changes. > @@boxcols= line.length-1 > else > boardlist += line.split(//).collect{|n| n.hex } > size = line.length > end > p line > end > boardlist,size > end It's definitely looking more Rubyish, I would say. Have a look at how the other solutions parsed the input, if you want to compare. James Edward Gray II