Bird
0
0

In Ruby, what type of value does File.read('file.txt') return?

easy📝 Conceptual Q1 of 15
Ruby - File IO
In Ruby, what type of value does File.read('file.txt') return?
AA hash with line numbers as keys
BAn array of strings, each representing a line
CA file object for further reading
DA single string containing the entire file content
Step-by-Step Solution
Solution:
  1. Step 1: Understand File.read

    The Ruby method File.read reads the entire content of the file as a single string.
  2. Step 2: Differentiate from other methods

    Methods like File.readlines return an array of lines, but File.read returns one string.
  3. Final Answer:

    A single string containing the entire file content -> Option D
  4. Quick Check:

    File.read returns a string [OK]
Quick Trick: File.read returns full content as one string [OK]
Common Mistakes:
  • Confusing File.read with File.readlines
  • Expecting a file object instead of string
  • Thinking it returns a hash or other data structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes