Module: Kutils::FileUtils
- Defined in:
- lib/utils/file_utils.rb
Overview
FileUtils provides safe file and directory operations. ⚠️ 注意:如与 Ruby 标准库 FileUtils 冲突,可改名为 SafeFileUtils。
Class Method Summary collapse
-
.mkdir_p(path) ⇒ void
Create directory if not exists.
-
.safe_read(path) ⇒ String?
Safely read file content if file exists.
Class Method Details
.mkdir_p(path) ⇒ void
This method returns an undefined value.
Create directory if not exists
25 26 27 |
# File 'lib/utils/file_utils.rb', line 25 def self.mkdir_p(path) Dir.mkdir(path) unless Dir.exist?(path) end |
.safe_read(path) ⇒ String?
Safely read file content if file exists
16 17 18 |
# File 'lib/utils/file_utils.rb', line 16 def self.safe_read(path) File.exist?(path) ? File.read(path) : nil end |