Bird
0
0

You want to change the current working directory to projects, create a new folder new_app inside it, and then list the contents of projects. Which sequence of Ruby commands correctly does this?

hard📝 Application Q15 of 15
Ruby - File IO
You want to change the current working directory to projects, create a new folder new_app inside it, and then list the contents of projects. Which sequence of Ruby commands correctly does this?
ADir.chdir('projects') Dir.mkdir('new_app') puts Dir.entries('.')
BDir.mkdir('new_app') Dir.chdir('projects') puts Dir.entries('new_app')
CDir.entries('projects') Dir.mkdir('new_app') Dir.chdir('new_app')
DDir.chdir('new_app') Dir.mkdir('projects') puts Dir.entries('.')
Step-by-Step Solution
Solution:
  1. Step 1: Change directory to 'projects'

    Using Dir.chdir('projects') sets the current directory to 'projects'.
  2. Step 2: Create 'new_app' inside 'projects'

    Dir.mkdir('new_app') creates the new folder inside the current directory.
  3. Step 3: List contents of current directory

    Dir.entries('.') lists all files and folders inside 'projects', including 'new_app'.
  4. Final Answer:

    Dir.chdir('projects') Dir.mkdir('new_app') puts Dir.entries('.') -> Option A
  5. Quick Check:

    Change dir, create folder, list contents = Dir.chdir('projects') Dir.mkdir('new_app') puts Dir.entries('.') [OK]
Quick Trick: Change dir first, then create folder, then list with Dir.entries('.') [OK]
Common Mistakes:
  • Creating folder before changing directory
  • Listing wrong directory contents
  • Changing to new folder before creating it

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes