Prompt: How is Object Oriented Ruby a metaphor for life?

This is a really fun thought to have, because the first reaction is:

“Uh, it’s not?”

But that’s not true at all. In fact, OO in general is a mirror of life itself, especially once you learn of the meta-programming aspect.

The first thing I realized is how much of life is compartmentalization and efficiency, and how that also applies to Ruby (or really any language you learn). Doing too much at once gets really messy. Imagine you had to pick up groceries, drop dry cleaning, then cook dinner. If you try to do one while doing the other, like trying to cook before you bought all the groceries, you’re neglecting the very action you’re doing because you’re not completely occupied with it. Or if you try to pick up dry cleaning while you’re trying to cook, you may well start a block fire. It’s the same in programming.

If I had a method #my_day, and tried to program each individual part I specified above as it came to me, it would be a mess.

def my_day
self.drive(distance_to_Grocers)
self.buy_groceries({"Banana" => 5, "Garlic" => 1, "Toothpaste" => "Only if it's on sale"})
self.think("Did I drop off the dry cleaning? No not yet. When should I do that? What should I cook for dinner?")
self.forget(coupons:)
...

That would laborious very quickly. But what if instead of running life at the whim of your first thought process, you instead thought about your day abstractly first, and then sequenced each part of it? It suddenly becomes a lot more manageable.

def my_day
self.buy_groceries(grocerylist,coupons)
self.pick_up_drycleaning
self.cook_dinner(recipe,groceries)
end

It suddenly gets a lot easier to follow. And easier to manage. And shorter.

Think about a class called Me.
For lack of a better term, this class is any of us. And when a new one of you is made, it contains every single thing about you. Every hope, every favorite, every t-shirt, every hobby. And Me is cool with that, because it uses attributes.each {|key,value| self.send{"#{key}=",value}

But not every single person will ever go through the depths of your key value pairs. It will take the parts it knows exists from you: your shirt color, your hairstyle, the shoes on your feet. There’s no way to fully know the depths of you without spending time with you, working with you, and getting to understand you (much like doing a Learn.co lab on you). So while one person might use you for something…

Sam.borrow("$20")

Other people may find a better use for you…

Sam.befriend

And that’s what OO programming, and life, have in common. Finding your best use.


Posted

in

by

Tags: