From: Kyle Schmitt Date: 2008-05-02T03:46:09+09:00 Subject: Re: splitting with a regex & keeping a ref? David, I don't mind it at all! Out of curiosity, agreeing that File.read().scan() is much cleaner, is it just syntactic sugar for the same thing, or is it computationally different? Thanks for the Hash[*Array] syntax btw, I've used it way way back, but for the life of me couldn't remember it, thought maybe I was mistaken. > I know you're not asking for refactoring advice, but here's some > anyway :-) > > If you're just going to read a file's contents into a string, you can > use File.read, rather than the whole open/read thing. Also, I'd > encourage you to drop the empty parentheses after method names. The > message-sending dot tells you that it's a method; the () doesn't add > signal, just noise. > > Anyway, here's a tweaked version, in case it's of interest. Nothing > too radical, just a couple of possibly fun alternative techniques :-) > > File.read("filename").scan(regex) do |title,options| > samba_config[title] = {} > options.strip.each do |option| > samba_config[title].update(Hash[*option.strip.split(/\s*=\s*/)]) > end > end > > > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > See http://www.rubypal.com for details and updates! > >