โ† Ruby Programming learning path
Ruby Programming ยท Module 7 of 10

Classes and objects

Ruby is object-oriented: classes create objects with state and behaviour.

๐Ÿ“– Key ideas

  1. class Student ... end defines a class; Student.new creates an object.
  2. initialize runs when an object is created.
  3. Instance variables start with @, like @name.
  4. attr_accessor :name creates getter and setter methods.
  5. Inheritance: class Intern < Student.
๐Ÿ’ก Real-life example: A class is the admission form template; each filled form is an object with its own details.
initializeConstructor method
@nameAn instance variable
attr_accessorCreates getter and setter
<Inherit from a parent class