Bird
0
0

Why might using module_eval with strings be risky or discouraged in some Ruby applications?

hard📝 Conceptual Q10 of 15
Ruby - Advanced Metaprogramming

Why might using module_eval with strings be risky or discouraged in some Ruby applications?

ABecause it always causes syntax errors
BBecause it can execute arbitrary code leading to security vulnerabilities
CBecause it prevents method overriding
DBecause it makes modules immutable
Step-by-Step Solution
Solution:
  1. Step 1: Understand risks of evaluating strings as code

    Using module_eval with strings executes code dynamically, which can be dangerous if the string content is not trusted.

  2. Step 2: Analyze options

    Because it can execute arbitrary code leading to security vulnerabilities correctly identifies security risks. Options A, C, and D are incorrect or unrelated.

  3. Final Answer:

    Because it can execute arbitrary code leading to security vulnerabilities -> Option B
  4. Quick Check:

    String eval risks = Security vulnerability [OK]
Quick Trick: Avoid untrusted strings in module_eval to prevent security issues [OK]
Common Mistakes:
  • Thinking it always causes syntax errors
  • Believing it prevents method overrides
  • Assuming modules become immutable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes