Second block parameter of Pathname#glob to be relative path from self
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) 10 months 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 Dan0042 (Daniel DeLorme) 10 months 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
Updated by jeremyevans0 (Jeremy Evans) 10 months 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.