0
0
Rubyprogramming~5 mins

Dir operations for directories in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Ruby Dir.pwd method return?
It returns the current working directory as a string. Think of it as asking, "Where am I right now in the folder system?"
Click to reveal answer
beginner
How do you list all files and folders inside a directory using Ruby?
Use Dir.entries(path). It returns an array of all entries (files and folders) inside the given directory path.
Click to reveal answer
intermediate
What is the difference between Dir.entries and Dir.glob?
Dir.entries lists everything inside a directory. Dir.glob lets you use patterns (like *.txt) to find specific files.
Click to reveal answer
beginner
How do you change the current working directory in Ruby?
Use Dir.chdir(path). It moves your program's focus to the folder you specify, like changing rooms in a house.
Click to reveal answer
beginner
What does Dir.mkdir('folder_name') do?
It creates a new directory (folder) named 'folder_name' in the current location. Like making a new folder in your filing cabinet.
Click to reveal answer
Which Ruby method returns the current working directory?
ADir.chdir
BDir.pwd
CDir.entries
DDir.mkdir
How do you list all files and folders inside a directory in Ruby?
ADir.chdir
BDir.mkdir
CDir.entries
DDir.pwd
Which method lets you change the current working directory?
ADir.chdir
BDir.pwd
CDir.glob
DDir.entries
What does Dir.mkdir('new_folder') do?
ACreates a new folder
BDeletes a folder
CLists files
DChanges directory
Which method allows you to find files matching a pattern like '*.rb'?
ADir.mkdir
BDir.entries
CDir.pwd
DDir.glob
Explain how to list all files in a directory and how to filter files by extension using Ruby Dir methods.
Think about how you can see everything first, then pick specific files.
You got /4 concepts.
    Describe how to change the current working directory and create a new directory in Ruby.
    Imagine moving to a new room and making a new box inside it.
    You got /4 concepts.