Feature #16621
openSecond block parameter of Pathname#glob to be relative path from self
Description
I often write such a code:
some_dir = Pathname("some/dir")
some_dir.glob("**/*.html") do |path|
rel_path = path.relative_path_from(some_dir)
# ...
end
If Pathname#glob yields the relative path from self as a second block parameter, I can write the above as follows:
Pathname("some/dir").glob("**/*.html") do |path, rel_path|
# ...
end
Updated by shevegen (Robert A. Heiler) almost 5 years ago
(Just trying to get some more details - I have no particular opinion per se as I
tend to almost exclusively use Dir[] myself, so this is more for ruby users who
use Pathname in general.)
Would this change have any potential backwards incompatibility/problem? This is
a genuine question, by the way, I really don't know, since I don't use Pathname
since many years, and I have no pro/con opinion about the suggestion itself.
Updated by 5.5 (5 5) almost 5 years ago
I think no problem in the backward compatibility.
If we use the proposed glob method with one block parameter, it behaves same as the current glob method.
Updated by Dan0042 (Daniel DeLorme) almost 5 years ago
What you want is this:
Dir.glob("**/*.html", base: "some/dir")
It would be nice if this was exposed via Pathname. There's something weird with the documentation for Pathname#glob though; it says "This method uses the base keyword argument of Dir.glob." but this doesn't appear to be true. Dir.glob(g, base: p)
is not the same as p.glob(g)
Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago
5.5 (5 5) wrote in #note-2:
I think no problem in the backward compatibility.
If we use the proposed glob method with one block parameter, it behaves same as the current glob method.
This is incorrect if the block passed is a lambda.
Updated by 5.5 (5 5) almost 5 years ago
jeremyevans0 (Jeremy Evans) wrote in #note-4:
This is incorrect if the block passed is a lambda.
Oops. You are right.
My proposal contains the backward incompatibility.
So some option is needed ...?
Updated by 5.5 (5 5) almost 5 years ago
Dan0042 (Daniel DeLorme) wrote in #note-3:
What you want is this:
Dir.glob("**/*.html", base: "some/dir")
Thank you for your suggestion.
But I want both its absolute path and its relative path from self.