Bird
0
0

Why does running ruby -e 'puts "Hello"' work without a script file?

hard📝 Conceptual Q10 of 15
Ruby - Basics and Runtime
Why does running ruby -e 'puts "Hello"' work without a script file?
ABecause it opens an interactive shell
BBecause Ruby creates a temporary script file automatically
CBecause -e executes the given code string directly
DBecause it runs the last saved script
Step-by-Step Solution
Solution:
  1. Step 1: Understand the -e option in Ruby

    The -e option tells Ruby to execute the code string provided directly from the command line.
  2. Step 2: Confirm behavior without script file

    This allows running small Ruby code snippets without needing a separate file.
  3. Final Answer:

    Because -e executes the given code string directly -> Option C
  4. Quick Check:

    -e runs code string directly without file [OK]
Quick Trick: Use -e to run Ruby code directly from command line [OK]
Common Mistakes:
  • Thinking Ruby creates temp files
  • Confusing with interactive shell
  • Assuming it runs last script

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes