0Pricing
Ruby Academy · Lesson

Instance Variables and Methods

Understand how objects store data and interact with methods inside a class.

1

Instance Variables and Methods

Instance variables store object-specific data, and instance methods allow objects to interact with their data.

In this lesson, you will learn how instance variables and methods work in Ruby classes.

Instance Variables and Methods — illustration 1

2

What are Instance Variables?

Instance variables store data specific to an object and start with @.

class Person
  def initialize(name)
    @name = name
  end
end

person1 = Person.new('Alice')

All lessons in this course

  1. Classes and Objects
  2. Instance Variables and Methods
  3. Inheritance and Polymorphism
  4. Mixins and Modules
← Back to Ruby Academy