Project

General

Profile

Actions

Misc #14905

closed

Strange behavior in Dir.glob using ** operator

Added by trobinson (Trevor Robinson) almost 6 years ago. Updated almost 6 years ago.

Status:
Rejected
Assignee:
-
[ruby-core:87895]

Description

Hello,

I didn't want to report this as a bug because I'm not sure if it's intentional or not. The documentation didn't say either way. The ** operator appears to work somewhat strangely when used in certain contexts.

An example setup to trigger the odd behavior looks something like this:

human_records
 ├ person1 ─ records.yml
 └ person2 ─ other_records.yml

cloud_records
 ├ AWS ┬ project1 ─ records.yml
 │     └ project2 ─ records.yml
 └ Azure ─ azproj1 ─ records.yml

Though the documentation doesn't say to do this, because of my experience with other globbing libraries, I did the following:

Dir.glob("human_records/**.{yml,yaml}")
# => ["human-records/person1/records.yml", "human_records/person2/other_records.yml"]

Dir.glob("cloud_records/**.{yml,yaml}")
# => []

So using ** like this works if there is only one level of folders between the root and the target files, as if the glob was "records/*/*.{yml,yaml}".

This seems like undefined behavior, so I thought I would bring it to your attention. If a change isn't a good solution to this, would a note in the documentation about undefined behavior around ** be warranted?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0