Ruby - Classes and ObjectsWhich of the following best describes attr_accessor in Ruby?ACreates both getter and setter methods for an instance variable.BCreates only a setter method for an instance variable.CCreates a method to delete an instance variable.DCreates only a getter method for an instance variable.Check Answer
Step-by-Step SolutionSolution:Step 1: Recall attr_accessor purposeattr_accessor creates both getter and setter methods, allowing reading and writing of instance variables.Step 2: Compare with attr_reader and attr_writerattr_reader creates only getter, attr_writer only setter, attr_accessor does both.Final Answer:Creates both getter and setter methods for an instance variable. -> Option AQuick Check:attr_accessor = getter + setter [OK]Quick Trick: attr_accessor gives read and write access [OK]Common Mistakes:Thinking attr_accessor creates only one methodConfusing attr_accessor with attr_reader or attr_writerAssuming attr_accessor deletes variables
Master "Classes and Objects" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Lambda creation and behavior - Quiz 14medium Blocks, Procs, and Lambdas - Why blocks are fundamental to Ruby - Quiz 10hard Class Methods and Variables - Frozen objects - Quiz 11easy Enumerable and Collection Processing - Group_by for categorization - Quiz 6medium Enumerable and Collection Processing - Zip for combining arrays - Quiz 3easy Error Handling - Exception hierarchy - Quiz 5medium File IO - Dir operations for directories - Quiz 4medium Inheritance - Why single inheritance in Ruby - Quiz 11easy Modules and Mixins - Custom modules as mixins - Quiz 15hard Modules and Mixins - Module declaration syntax - Quiz 5medium