More About Parent Classes
Tonight I guess I should tell you a bit more about parent classes and why you need them.
Do you really need them?

Code:
class Rect
def initialize(x, y, w, h)
@x = x
@y = y
@width = w
@height = h
end
attr_accessor :x, :y, :width, :height
end
Do you see that? It's our basic Rect(angle) class!




Right...


Yeah, you could later come up with other classes like other shapes, namely Circle, Triangle, and so on. Honestly you can stick to rectangles only for most of your gaming needs. At the end, you won't deal with any other geometrical shape unless you start using something like OpenGL and start depending on your graphics cards capabilities.

So how do you know when to subclass some bunch of code? Here's when you should do that!
Code:
class Person
def initialize(name)
@name = name
@age = 0
@ssid = "0"
@job = ""
@skin_color = Color.new(0,0,0)
@eye_color = Color.new(0,0,0)
@hair_color = Color.new(0,0,0)
@hobbies = []
@relatives = []
@phone_number = ""
end
attr_accessor :name, :age, :ssid, :job, :skin_color, :eye_color, :hair_color, :phone_number
attr_reader :hobbies, :relatives
end
Do you know every single person share stuff in common?
I guess so...

Well, that could later become our first parent class!
How so!?

That's easy to explain! We know many people share traits like name, age, skin, eyes, hair, and so on. With this we can already create an object to represent a person like a student or coworker or site administrator or just some dreamer that complains about heat and many more!
So what's next?


Code:
class Gamer < Person
def initialize(name)
super
@played_games = []
@favorite_games = []
@despised_games = []
@hours_spent_gaming = 0
end
attr_reader :played_games, :favorite_games, :despised_games
attr_accessor :hours_spent_gaming
end


Yeah, I did!

Go ahead!


Code:
class Lawyer < Person
def initialize(name)
super(name)
@degree = ""
@got_license = true
@location = ""
@workdays = []
@customers = []
@work_phone_number = ""
end
attr_accessor :degree, :got_license, :work_phone_number
attr_reader :workdays, :customers
end
As you can see a lawyer, even if nobody likes them except for their own families








O_o? Are they!? Anyway, I've proven that we might need a basic parent class in case we might later define several descendants that will need to call stuff defined in the parent class. This pattern will save us from adding many checks in our code just to define when a person should turn on a TV set or open a briefcase or yell Objection! You wouldn't do that if you were just sitting on a seat like many other passengers while traveling on a bus or train or metro, would you!?

Now we're gonna discuss what's super!





Actually for Ruby none of them would be super.

Yeah, none of them are, I do agree with Ruby on this.




Code:
class Siletrea < WannabeDragonfly
def initialize(name)
@name = name
@claws = []
@age = 0
@favorite_habitat = ""
end
attr_accessor :name, :age, :favorite_habitat
attr_reader :claws
end
Wait a second!







By the way, just in case you include arrays or hashes in your classes, you'd usually need getters only. Most of the time you'd just change their contents, not the entire array or hash. Thus there's no need to define something you don't need. That will keep your code clean and won't ask for extra resources that are gonna get wasted anyway.

How large can a class ever be?
Err, again, that depends on your project and coding style.





Warning!
Don't abuse of loops or you'll get stuck in no time! 

Happy Stack Overflow!

"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-PixelArtist.png]](https://www.save-point.org/images/userbars/SP1-PixelArtist.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE