On Aug 14, 2:40 am, "nikolai.weib... / gmail.com"
<nikolai.weib... / gmail.com> wrote:
> Hi!
>
> I wanted to write a simple method for comparing two paths on a Windows
> system.  My initial algorithm felt very contrived:
>
> def same_path?(a, b)
>   a, b = [a, b].map{ |p| File.expand_path(p).downcase }
>   a == b
> end
>
> It felt like saving the result from #map and then doing the comparison
> shouldn't be necessary.  So I came up with the following solution:
>
> class Array
>   def apply(method)
>     shift.send(method, *self)
>   end
> end
>
> This allowed me to define #same_path? thusly:
>
> def same_path?(a, b)
>   [a, b].map{ |p| File.expand_path(p).downcase }.apply(:==)
> end

Your first solution is much easier to understand. In fact I would do:

 def same_path?(a, b)
   a = File.expand_path(a).downcase
   b = File.expand_path(b).downcase
   a == b
 end

It's very clear and actually should be a tad faster. LOC isn't
everything!

But if you just can't abide by more that one line:

 def same_path?(a, b)
   File.expand_path(a).downcase == File.expand_path(b).downcase
 end

HTH,
T.