create a directory in ruby

To create a directory in Ruby, you can use the Dir.mkdir method or the FileUtils.mkdir method (which provides more advanced options and error handling). Here's an example using Dir.mkdir:

main.rb
dir_name = "my_new_directory"
Dir.mkdir(dir_name)
50 chars
3 lines

This will create a new directory with the name "my_new_directory" in the current working directory.

And here's an example using FileUtils.mkdir:

main.rb
require 'fileutils'
dir_name = "my_new_directory"
FileUtils.mkdir(dir_name)
76 chars
4 lines

This will also create a new directory with the name "my_new_directory" in the current working directory, but FileUtils.mkdir provides more options for handling errors and creating parent directories if they don't exist.

gistlibby LogSnag