Skip to content

Add support of sort argument as nil for Dir.glob #5079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Strech
Copy link

@Strech Strech commented Nov 4, 2021

Right now Dir.glob("*", sort: nil) will produce the same result as Dir.glob("*", sort: true).

irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: true)
=> ["brace/a.js", "brace/a", "brace/a.erb", "brace/a.html.erb", "brace/a.js", "brace/a.js.rjs"]

irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: false)
=> ["brace/a.js", "brace/a.js", "brace/a.html.erb", "brace/a.erb", "brace/a.js.rjs", "brace/a"]

irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: nil)
=> ["brace/a.js", "brace/a", "brace/a.erb", "brace/a.html.erb", "brace/a.js", "brace/a.js.rjs"]

After this patch both Dir.glob("*", sort: false) and Dir.glob("*" sort: nil) will produce identical unsorted results.

Current behaviour was noted here: ruby/spec#894 and @eregon suggested addressing it bugs#18287

Right now `Dir.glob("*", sort: nil)` will produce the same result as
`Dir.glob("*", sort: true)`.

```
irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: true)
=> ["brace/a.js", "brace/a", "brace/a.erb", "brace/a.html.erb", "brace/a.js", "brace/a.js.rjs"]

irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: false)
=> ["brace/a.js", "brace/a.js", "brace/a.html.erb", "brace/a.erb", "brace/a.js.rjs", "brace/a"]

irb(main):001:0> Dir.glob("brace/a{.js,*}", sort: nil)
=> ["brace/a.js", "brace/a", "brace/a.erb", "brace/a.html.erb", "brace/a.js", "brace/a.js.rjs"]
```

After this patch both `Dir.glob("*", sort: false)` and `Dir.glob("*"
sort: nil)` will produce identical unsorted results.
@@ -2937,7 +2937,7 @@ dir_glob_option_base(VALUE base)
static int
dir_glob_option_sort(VALUE sort)
{
return (sort ? 0 : FNM_GLOB_NOSORT);
return ((NIL_P(sort) || sort == Qfalse) ? FNM_GLOB_NOSORT : 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is RTEST, so a nicer way here is !RTEST(sort) or better swap the branches so there is no !.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, will wait a while

@nobu nobu closed this Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants