What Ruby Concept Took You the Longest to Understand?

What Ruby Concept Took You the Longest to Understand? Blocks? Metaprogramming? Enumerators Object model?

1 Like

Blocks were hard to understand for me.

1 Like

yield by a wide margin :laughing:

2 Likes

blocks, lambdas, yield and procs are def very tricky ones.

A concept I’ve been struggling with is pattern matching! It’s still find it hard to get a good grasp on when and how to use them in the wild. Does anyone have experience using them? Is there a resource you would recommend?

1 Like

Pattern matching for me too. Part of the difficulty is that pattern matching is so rarely used even now a few years after it was released.

3 Likes

This was ages ago so going on flakey memory, but I feel like it was the whole include vs extend, and definitely blocks as well.

3 Likes

The whole life cycle of class level DSLs, when code is ran and how things are stored. When you start with Rails it’s everywhere and you don’t really need to know how it works under the hood. It’s so elegant and sometimes still feels like magic.

2 Likes
  • include, extend, and the class << self idiom
  • Class-level instance variables gotchas, and access specifiers (public/private) “surprises”, mainly due to prior exposure to other languages’ OOP model (like Java)

And not a concept per se, but I keep messing the order of arguments in reduce with a block when not using code-assistance :slight_smile:

3 Likes

Metaprogramming. It wasn’t difficult for me to understand the concept and it’s implementation in Ruby by itself, but it was really hard to learn when to do metaprogramming. I started programming (or getting paid for it) at a very young age, and at my first job I used to feel overwhelmed by how little I knew compared to the other devs (mind you it was a small endeavor startup just starting to grow so the senior devs didn’t really had the time or will to mentor me), so in my mind I had to learn and use the most complicated concepts possible to “blend in”. That’s how I started using metaprogramming, and the last thing I wish on earth is to have to revisit that code. I remember using metaprogramming to process huge dynamic and nested forms, which was quite literally impossible to debug. I still don’t understand how that went into production and passed the code reviews, and I do wonder if that code is still live years after I left the company

@lautarograc Metaprogramming can be very helpful and powerful, but it’s easy to abuse it and create code very difficult to understand. I think nowadays it’s mostly used in frameworks or DSLs. I think we’ve all have written code that keeps us awake at night, but it’s part of the learning process!

1 Like

I like to compare metaprogramming to spices in food: the right amount can create an amazing dish; too much, and you’ll end up with a queasy stomach. :joy:

That being said, metaprogramming is a really fun and useful concept.

2 Likes