This is an exam study question. I have to write a program in Ruby without mutati
ID: 3813797 • Letter: T
Question
This is an exam study question. I have to write a program in Ruby without mutation (using functional operations):
Input: a text file:
-Each line is a record.
-Each record contains one or more fields.
-Each field is separated by a semi-colon.
Example (3 fields):
- 12345;this is the second field;3
-The first field is either:
-empty (empty string) or
-a valid number
Output:
• Print the record with the largest number in the first field
• If two records have the same value, output only the first
• Ignore records with an empty first field
• Output is empty if no records or only records with an empty field
Thanks for your help!
Explanation / Answer
In this class, not only does the update method change the state of the object, but we've exposed our attrs hash through a public attr_accessor, leaving it easily exposed for mutation in place. What's the problem? Well, maybe nothing if the scope of this object is localized enough so that everything using the object knows that it could change. But once the mutations leave a defined boundary, we've introduced more complexity to the codebase.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.