Bird
0
0

Given a list of user objects, how can you use functional patterns with OOP to create a new list of usernames in Ruby without changing the original user objects?

hard📝 Application Q9 of 15
Ruby - Functional Patterns in Ruby
Given a list of user objects, how can you use functional patterns with OOP to create a new list of usernames in Ruby without changing the original user objects?
AUse map to extract usernames into a new array, leaving original objects unchanged.
BModify each user object to add a username attribute.
CDelete all user objects and create new ones with usernames.
DUse a loop to print usernames without storing them.
Step-by-Step Solution
Solution:
  1. Step 1: Identify functional pattern for transformation

    map creates a new array by applying a block to each element without modifying originals.
  2. Step 2: Apply map to user objects

    Extract usernames with map, producing a new list and preserving original objects.
  3. Final Answer:

    Use map to extract usernames into a new array, leaving original objects unchanged. -> Option A
  4. Quick Check:

    map creates new list without changing originals [OK]
Quick Trick: Use map to transform without mutation [OK]
Common Mistakes:
  • Modifying original objects instead of creating new data
  • Deleting objects unnecessarily
  • Only printing without storing results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes