โ Ruby Programming learning pathRuby Programming ยท Module 7 of 10
Classes and objects
Ruby is object-oriented: classes create objects with state and behaviour.
๐ Key ideas
- class Student ... end defines a class; Student.new creates an object.
- initialize runs when an object is created.
- Instance variables start with @, like @name.
- attr_accessor :name creates getter and setter methods.
- 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