Ruby File Class and Rails FileUtils

Now, after about 2 weeks of learning Ruby and Rails, I found the File class for things like File.join , File.open , etc. Then I came across the need only for File.copy to find out that such a method does not exist. A little more looking Rails FileUtils class, and now I'm a little confused.

Of course, there are differences, but there is something that seems redundant. Is preferred over others where there are differences? Why do both exist (only to handle omissions in the main Ruby class)?

I just wanted to understand how these things work together or conflict, so I know how to move forward.

Thanks.

+6
ruby ruby-on-rails
source share
1 answer

FileUtils is part of the Ruby Core API. This is not Rails. It is also a module, so you can mix some of the abilities that it can offer in another class. Your best bet is probably to read File RDoc as well as FileUtils RDoc . Hope this helps you. Greetings.

Edit:

Is preferred over others where there are differences?

I don’t know if there is a lot of consensus on use when the methods have the same end result, for example File.makedirs vs. FileUtils.mkdir_p , but I often see the latter in the code of other nations. I think you will almost always use two ( File and FileUtils ) together.

+7
source share

All Articles