Looking for more to read? Check out the Archives!

Ruby Blocks Epiphany

Rob Sobers, author of Learn Ruby the Hard Way, outlines some very interesting discoveries about Ruby blocks:

Here was the major realization I had about blocks: without understanding the inner-workings of the method I’m passing a block to, I can’t really write my block.

I couldn’t treat it as a black box, as badly as I wanted to. With many methods (or APIs), I can simply pass in arguments and get a return value without ever having to understand what actually goes on inside. And that encapsulation is a beautiful thing.

But with blocks, I am actively participating in writing the method I’m calling, so I have to understand the context in which my code is called. I also have to understand the objects that are yielded to my block via its arguments.

Check it out here

What struck me about this is that Ruby blocks looked simple to me at first; more or less like anonymous functions in Javascript. Ruby syntax is often described as “simple” or “good for beginners,” and I think that is an element of truth to that.

I wouldn’t call myself an expert in Javascript, but I have been using it for years, and because of that, I felt comfortable with Ruby when I started learning it. Like Javascript, Ruby treats everything as an object. And many of the methods and concepts are familiar. But there is also a level of subtlety and depth to Ruby that intrigues me. I have a lot to learn, but that excites me!

It’s like that with anything you choose to learn. If you look at all of the things you have to learn, it can be overwhelming. At first, when you know nothing, it’s easy to see improvements, but there inevitable peaks and valleys throughout the learning process. Sometimes, it seems like you’re actually getting worse! I’m lucky, because of my experience learning two Asian languages. I had people tell me I couldn’t do it, and sometimes, I might have believed them, but for the belief that with regular practice and determination, there’s almost no limit to what I can learn. It’s that spirit of optimism and self-confidence that continues to invigorate me and push me on to tackle new challenges.

As long as I am alive, I never want to stop learning and improving. And that is why I am so drawn to this field. You simply cannot stand still, or you’ll fall behind.


If you enjoyed this post, you might want to subscribe, so you don't miss the next one!