Bird
0
0

Which statement about Ruby's OpenStruct is TRUE?

hard📝 Conceptual Q10 of 15
Ruby - Metaprogramming Fundamentals
Which statement about Ruby's OpenStruct is TRUE?
AOpenStruct objects are immutable once created
BOpenStruct attributes can only be accessed using hash syntax
COpenStruct requires all attributes to be defined in advance
DOpenStruct allows adding and changing attributes dynamically at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Recall OpenStruct behavior

    OpenStruct objects allow dynamic addition and modification of attributes anytime.
  2. Step 2: Evaluate each statement

    Immutability claim is false; objects are mutable. Hash syntax only is false; uses dot notation. All attributes predefined is false; dynamic addition allowed. Adding and changing dynamically at runtime is true.
  3. Final Answer:

    OpenStruct allows adding and changing attributes dynamically at runtime -> Option D
  4. Quick Check:

    OpenStruct mutability and dynamic attributes = true [OK]
Quick Trick: OpenStruct attributes are dynamic and mutable [OK]
Common Mistakes:
  • Thinking OpenStruct is immutable
  • Assuming attributes must be predefined
  • Using hash syntax for access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes