Feature #16621
open
Second block parameter of Pathname#glob to be relative path from self
Added by 5.5 (5 5) almost 5 years ago.
Updated almost 5 years ago.
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
(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.
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.
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)
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.
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 ...?
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.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0