Ruby - File IOHow can you append text to an existing file "append.txt" using File.write?AFile.write("append.txt", "More text")BFile.write("append.txt", "More text", append: true)CFile.write("append.txt", "More text", mode: "w+")DFile.write("append.txt", "More text", mode: "a")Check Answer
Step-by-Step SolutionSolution:Step 1: Recall File.write options for modeTo append, use mode: "a" to open file in append mode.Step 2: Identify correct optionFile.write("append.txt", "More text", mode: "a") correctly uses mode: "a" to append text.Final Answer:File.write("append.txt", "More text", mode: "a") -> Option DQuick Check:Use mode: "a" to append with File.write [OK]Quick Trick: Use mode: "a" to append text with File.write [OK]Common Mistakes:Using default mode which overwritesUsing invalid option append: trueUsing mode "w+" which overwrites or truncates
Master "File IO" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Class Methods and Variables - Class variables (@@) and their dangers - Quiz 8hard Classes and Objects - Class declaration syntax - Quiz 12easy Enumerable and Collection Processing - Any?, all?, none? predicates - Quiz 11easy Error Handling - Ensure for cleanup - Quiz 7medium Error Handling - Begin/rescue/end blocks - Quiz 14medium File IO - File.read for entire content - Quiz 8hard File IO - Dir operations for directories - Quiz 15hard File IO - Dir operations for directories - Quiz 2easy Inheritance - Why single inheritance in Ruby - Quiz 8hard Modules and Mixins - Module methods - Quiz 14medium