Issue #11302 has been updated by olivierlacan (Olivier Lacan).


red (Arnaud Rouyer) wrote:
> Basing myself on the GNU ls util, I propose supporting an :ignore key in the optional hash argument.

I very much like this. I just ran into this issue myself today having to remove `.` and `..` from `Dir.entries` output. 

I don't think the `ignore` option accepting a regex is fancy at all, it makes a ton of sense. An array should also be acceptable considering that `Dir.entries('.', ignore: %w[. ..])` would become equivalent to: 

```
Dir.entries('.') - %w[. ..]
```

I find it quite elegant, and certainly a lot more discoverable than GNU ls style arguments. :-)

----------------------------------------
Feature #11302: Dir.entries and Dir.foreach without [".", ".."]
https://bugs.ruby-lang.org/issues/11302#change-63666

* Author: naruse (Yui NARUSE)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Dir.entries returns an array of its content with "." and "..".
But as far as I met, almost all cases don't need them.

How about adding such new method or options?



-- 
https://bugs.ruby-lang.org/