< :the previous in number
^ :the list in numerical order
> :the next in number
P :the previous artilce (have the same parent)
N :the next (in thread)
|<:the top of this thread
>|:the next thread
^ :the parent (reply-to)
_:the child (an article replying to this)
>:the elder article having the same parent
<:the youger article having the same parent
---:split window and show thread lists
| :split window (vertically) and show thread lists
~ :close the thread frame
.:the index
..:the index of indices
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.