OOP example in Ruby: Pokémon class (Part 1)

Josué Estévez Fernández
2 min readJan 14, 2018

--

Week 3 of the Makers Academy pre-course is about to finish, and, as I promised in my previous article, today we are going to create a quick Pokémon game while we learn about object-oriented programming (OOP) in Ruby at the same time.

What are classes and why do we need them?

A class is, basically, a representation of a reality that we need in order to create our application. It allows us to encapsulate how this reality behaves and what attributes it has.

We get to model our class methods and objects, sending customised, specific methods as a message to other objects. This way, everything we create is intertwined and this gives us greater flexibility.

Below you will find two videos I recorded, sorted by increasing difficulty, that hopefully will illustrate why we need classes for various purposes.

Video 1: easy difficulty

Example of a class in Ruby: Pokemon class — Easy

Video 2: medium difficulty

Example of a class in Ruby: Pokemon class — Medium

Did you notice the difference between the scripts in Video 1 and Video 2?

Video 1

Video 2

Despite the fact that, in both videos, the scripts were doing pretty much the same, the second one looks cleaner and more readable already than the previous one.

For now, and until next week, there is one thing we know for sure…

Pikachu rocks!

If you enjoyed the content, make sure you follow me not to miss next week’s video. I will create a refactored version where we will go through the concept of abstraction. An additional class will be added too, guess what it will do?

The purpose of the following video will be to create a script that even your grandma will be able to read and understand.

Do not forget to click the claps button too, these are always much appreciated.

--

--