I am attempting to make a module that extends the functionality of the FileUtils class.
require 'fileutils'
module FileManager
extend FileUtils
end
puts FileManager.pwd
if I run this, I’ll get a private method 'pwd' called for FileManager:Module (NoMethodError) error
Update:
Why are these class methods included privately and how can I expose all of them without having to manually include each method as public class methods in the FileManager module?
It seems like the instance methods on
FileUtilsare all private (as mentioned in another answer here, that means they can only be called without an explicit receiver). And what you get when you include or extend is the instance methods. For example:It turns out all the methods we want on
FileUtilsare there twice, as private instance methods and also as public class methods (aka singleton methods).Based on this answer I came up with this code which basically copies all the class methods from
FileUtilstoFileManager:It’s not pretty, but it does the job (as far as I can tell).