ruby attr_accessor multiple variables

Using attr_accessor for Multiple Variables in Ruby

class Example
  attr_accessor :name, :age
end
  1. Define a Class:
  2. Use the class keyword followed by the class name.
  3. Example: class Example

  4. Use attr_accessor:

  5. Utilize the attr_accessor method to define getter and setter methods for the specified variables.
  6. Syntax: attr_accessor :variable1, :variable2, ...
  7. Example: attr_accessor :name, :age

  8. Specify Variables:

  9. List the variables for which getter and setter methods should be created, separated by commas.
  10. Example: :name, :age

This setup will generate getter and setter methods for the name and age variables within the Example class.