Andreas Semt
1/12/2005 5:04:00 PM
Nicholas Van Weerdenburg wrote:
> end is the end of an expression that returns an array.
>
> # this is quivalent.
> a=files.map do |file|
> ...
> end
> a.uniq
>
> # Since everything in ruby is an expression, you can do:
> files.map do |file|
> ...
> end.uniq
>
> # making the expression explicit...
> (files.map do |file|
> ....
> end).uniq
>
> Regards,
> Nick
>
Thanks Nick!
Nice Ruby code.
It's every time a pleasure to see a solution by Florian.
Greetings,
Andreas
> On Thu, 13 Jan 2005 01:15:25 +0900, Andreas Semt <as@computer-leipzig.de> wrote:
>
>>Florian Gross wrote:
>>
>>>def files_equal?(*files)
>>> files.map do |file|
>>> File.size file
>>> end.uniq.size <= 1 and
>>> files.map do |file|
>>> File.read file
>>> end.uniq.size <= 1
>>>end
>>>
>>
>>Could anybody please explain the "end.uniq.size" line?
>>Thanks!
>>
>>Greetings,
>>Andreas
>>
>>
>>>This ought to be slightly faster in the average case.
>>>
>>>Other optimizations would be reading the files line-wise in parallel and
>>>bailing out as soon as one of the lines differs.
>>>
>>
>>
>
>