Ruby Class vs Instance Method

So, what is an instance variable and instance method?

class Album

def release_date=(date)
@release_date = date
end

def release_date
@release_date
end
end
album = Album.new
album.release_date = 1991
album.release_date
# => 1991

What is a class variable and class method?

def self.countend

Well that then raises another question, what is self?

class Album
@@album_count = 4

def self.count
@@album_count
end
end
# You call it by writing:
Album.count

--

--

--

A software engineering student at Flatiron School.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Validating struct, map, form in GO language

High availability webserver architecture in AWS

Passing HTTP headers to another microservice and put them to the log programmatically using Spring…

What is YoMo? Which real problems does YoMo solve?

ChangeWindows 4.5

My guide to Alexa

How to Publish Your Spring Boot App to the Cloud

Running Ghost in a Multi-Region Google Kubernetes Engine

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jessica Sewell

Jessica Sewell

A software engineering student at Flatiron School.

More from Medium

Building a Ruby CLI app

Updating contents of GitHub repositories via Ruby

Making An External API Call Using Backend In A [React/Rails] App

Seeding a Rails Database with the YouTube Data API