find the name of a directory in ruby

To find the name of a directory in Ruby, you can use the File.basename method to get the last component of the given path.

Here's an example code block:

main.rb
directory_path = "/path/to/my/directory/"
directory_name = File.basename(directory_path)

puts directory_name
110 chars
5 lines

This code will output:

main.rb
directory
10 chars
2 lines

Where directory_path is the path of the directory, directory_name is the name of the directory and puts is used to print the output.

gistlibby LogSnag