Issue #12814 has been updated by Mr. Tao.


I see… Still I can't decide whether it is for good or not. What is the purpose of such a path then? Shouldn't a String object instead of a Pathname be returned in such a case?

In my scenario I traverse directories and process some of them. If `each_child(false)` still contained enough information about it's relative position in directory tree it would allow me make code below somewhat simpler and more readable. Perhaps augmenting the Pathname class with this information might be beneficial.

~~~ruby
…
    user_path.each_child do |mailbox_path|
        process_mailbox mailbox_path if mailbox_path.directory?
…
def process_mailbox(mailbox_path)
…
    mailbox_path.find do |f|
          if f.directory?
            process_folder(f)
            next
…
def process_folder(folder)
    @user.mailboxes.find_or_create_by_path((folder.relative_path_from @user_path).to_s.split(File::SEPARATOR))
…
~~~

----------------------------------------
Bug #12814: Pathname#each_child(false) produces unusable file paths
https://bugs.ruby-lang.org/issues/12814#change-60909

* Author: Mr. Tao
* Status: Feedback
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
I tried to iterate over items in a directory with `each_child` testing each item whether it is a directory or not with `directory?`. This was working just fine until I added **`false`** as an argument to `each_child`.

~~~ ruby
Pathname.new('.').each_child { |f| p f.realpath } #works as expected
Pathname.new('.').each_child(false) { |f| p f.realpath } # throws an error
~~~

As per Ruby doc "By default, the yielded pathnames will have enough information to access the files.", however pathnames yielded with `with_directory=false` are completely useless as file paths.



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>