Module: RBT::SaveFile
- Defined in:
- lib/rbt/toplevel_methods/files_and_directories_related_methods.rb
Overview
#
RBT::SaveFile
This file provides file-saving capabilities. This is already possible within ruby itself via File.open but I wanted to use a simpler API to memorize.
#
Class Method Summary collapse
-
.append_what_into(what, into) ⇒ Object
# === RBT::SaveFile.append_what_into ========================================================================= #.
-
.write_what_into(what, into, use_these_permissions = 0755) ⇒ Object
# === RBT::SaveFile.write_what_into.
-
.write_what_into_via_unicode(what, into, use_these_permissions = 0755) ⇒ Object
# === RBT.write_what_into_via_unicode.
Class Method Details
.append_what_into(what, into) ⇒ Object
#
RBT::SaveFile.append_what_into
#
1360 1361 1362 |
# File 'lib/rbt/toplevel_methods/files_and_directories_related_methods.rb', line 1360 def self.append_what_into(what, into) File.open(into, 'a') { |file| file.write(what) } end |
.write_what_into(what, into, use_these_permissions = 0755) ⇒ Object
#
RBT::SaveFile.write_what_into
This method can be used to write content into a file, via ruby’s File.open() functionality.
The official documentation can be found here:
https://ruby-doc.org/core/File.html#method-c-open
#
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
# File 'lib/rbt/toplevel_methods/files_and_directories_related_methods.rb', line 1375 def self.write_what_into( what, into, = 0755 ) case when :default = 0755 end base_dir = File.dirname(into) RBT.mkdir(base_dir) unless File.exist? base_dir File.open(into, 'w+', .to_i) { |file| file.write(what) } # RBT.e "No file exists at #{into}." end |
.write_what_into_via_unicode(what, into, use_these_permissions = 0755) ⇒ Object
#
RBT.write_what_into_via_unicode
This method will specifically make use of the ‘w:UTF-8’ flag.
#
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 |
# File 'lib/rbt/toplevel_methods/files_and_directories_related_methods.rb', line 1397 def self.write_what_into_via_unicode( what, into, = 0755 ) case when :default = 0755 end base_dir = File.dirname(into) RBT.mkdir(base_dir) unless File.exist? base_dir File.open(into, 'w:UTF-8', .to_i) { |file| file.write(what) } end |