From: Hristo Deshev Date: 2005-09-05T14:48:55+09:00 Subject: Re: Help me clean up this method ------=_Part_7676_24620864.1125899332319 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Daniel, On 9/5/05, Daniel Sheppard wrote: >=20 > This is cleaner to my eye, but YMMV. >=20 > |class Dir > | def size(name) > | Dir.chdir(name) > | Dir["**/*"].inject(0) do |total,name| > | total + (File.file?(name) ? File.size(name) : 0) > | end > | end > |end The ?: operator is indeed shorter. I am not sure if I like it better, but I= =20 will stick with it. Maybe extracting the file or dir size calculation to a= =20 separate method would be best. Also, be aware that you're changing the working dir and not changing it > back. >=20 > Are there situations where Dir[name + "/**/*"] wouldn't work? I can swear I tried that first and it did not return any files. Maybe I was= =20 missing a slash somewhere. It now works like a charm. Thanks for pointing i= t=20 out.=20 Hristo Deshev ------=_Part_7676_24620864.1125899332319--