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.rb110 chars5 lines
This code will output:
main.rb10 chars2 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