[ruby-core:124047] [Ruby Feature#21766] Pathname + FileUtils making sweet music together
Issue #21766 has been reported by gurgeous (Adam Doppelt). ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by Dan0042 (Daniel DeLorme). Remember that `FileUtils` is loaded dynamically, so it would be something like ```ruby class Pathname def mkdir_p(...) = _fileutils(:mkdir_p, ...) def ln(...) = _fileutils(:ln, ...) def ln_s(...) = _fileutils(:ln_s, ...) def ln_sf(...) = _fileutils(:ln_sf, ...) def cp(...) = _fileutils(:cp, ...) def cp_r(...) = _fileutils(:cp_r, ...) def mv(...) = _fileutils(:mv, ...) def rm(...) = _fileutils(:rm, ...) def rm_r(...) = _fileutils(:rm_r, ...) def rm_rf(...) = _fileutils(:rm_rf, ...) private def _fileutils(name, ...) require "pathname/fileutils" send(name, ...) end end #pathname/fileutils.rb require "fileutils" class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-115479 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by gurgeous (Adam Doppelt). I'm open to any and all implementation suggestions, happy to do whatever is required. I just want the feature! ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-115481 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by zverok (Victor Shepelev). I am thinking in this direction: it is not unseen for standard libraries, when required, to add methods to core objects: ```ruby {a: 1}.to_json # NoMethodError require 'json' {a: 1}.to_json #=> {"a": 1} Time.parse('12:20') # NoMethodError require 'time' Time.parse('12:20') #=> 2025-12-08 12:20:00 +0200 ``` Why not this, then? ```ruby Pathname('tmp.txt').cp('tmp/') # NoMethodError require 'fileutils' Pathname('tmp.txt').cp('tmp/') # Works ``` As `Pathname` have became core object, it seems to be OK for a library like `fileutils` to be aware of it and extend it? ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-115488 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by akr (Akira Tanaka). I feel Unix command names are too short for usual programs. So, I'm negative. ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-115623 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by zverok (Victor Shepelev).
I feel Unix command names are too short for usual programs.
At the same time: * they are known at least to most of the console-using programmers, so this is a "dictionary" many of us familiar with * FileUtils have a practice of aliasing them to more common words (`cp` as `copy`, `mv` as `move`, and so on) which Pathname can borrow, too. `Pathname.new('test.txt').move('tmp/')` is perfectly clear and unambiguous. ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-115636 * Author: gurgeous (Adam Doppelt) * Status: Open ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
Issue #21766 has been updated by hsbt (Hiroshi SHIBATA). Status changed from Open to Rejected https://github.com/ruby/pathname/issues/64 is closed now.
it seems to be OK for a library like fileutils to be aware of it and extend it?
I prefer this proposal. I think it would be better to do the same for Pathname methods that are not available at core class, but I haven't fully sorted out the issues yet. We should be discussed in a separate ticket. ---------------------------------------- Feature #21766: Pathname + FileUtils making sweet music together https://bugs.ruby-lang.org/issues/21766#change-116142 * Author: gurgeous (Adam Doppelt) * Status: Rejected ---------------------------------------- I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps? ``` ruby class Pathname def mkdir_p(...) = FileUtils.mkdir_p(@path, ...) def ln(...) = FileUtils.ln(@path, ...) def ln_s(...) = FileUtils.ln_s(@path, ...) def ln_sf(...) = FileUtils.ln_sf(@path, ...) def cp(...) = FileUtils.cp(@path, ...) def cp_r(...) = FileUtils.cp_r(@path, ...) def mv(...) = FileUtils.mv(@path, ...) def rm(...) = FileUtils.rm(@path, ...) def rm_r(...) = FileUtils.rm_r(@path, ...) def rm_rf(...) = FileUtils.rm_rf(@path, ...) end ``` There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it! (also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72) -- https://bugs.ruby-lang.org/
participants (5)
-
akr (Akira Tanaka) -
Dan0042 (Daniel DeLorme) -
gurgeous (Adam Doppelt) -
hsbt (Hiroshi SHIBATA) -
zverok (Victor Shepelev)