attr_reader do in Ruby?attr_reader creates a getter method for an instance variable. It lets you read the value but not change it directly.
attr_writer in Ruby?attr_writer creates a setter method for an instance variable. It lets you change the value but not read it directly.
attr_accessor in Ruby.attr_accessor creates both getter and setter methods for an instance variable. You can read and change the value.
attr_reader, attr_writer, or attr_accessor instead of writing methods manually?They save time and make code cleaner by automatically creating simple getter and setter methods.
attr_reader :name, can you change the @name variable directly from outside the class?No, attr_reader only allows reading the value. To change it, you need a setter method like attr_writer or attr_accessor.
attr_accessor creates both getter and setter methods, allowing reading and writing.
attr_writer :age provide?attr_writer creates a setter method to change the value of @age.
attr_reader :title, what happens if you try to assign obj.title = 'New'?Without a setter method, assigning to title raises a NoMethodError.
attr_accessor?attr_accessor does not make variables private; it creates public getter and setter methods.
attr_reader, attr_writer, and attr_accessor?These methods are public by default, accessible from outside the class.
attr_reader, attr_writer, and attr_accessor in Ruby.attr_accessor can make your Ruby class code cleaner and easier to maintain.