Idiomatic Ruby

Hello guys,

As all of you, I think Ruby a beautiful programming language. And I wrote a blog post about that.

I call it Idiomatic Ruby

Any comment or advice will alwasy be welcome :slight_smile:

Nice post. But you shouldn’t use any? to test if a collection is empty. To see why try it on this array: [nil, false] and read the docs. Use empty? to test if an array is empty.

Hey Scott,

You’re absolutely right. If we want to ask an array if it is empty, we can use the .empty? method. But if we want to ask if the array has anything inside it, we can use .any? method :slight_smile:

That’s not what #any? is for, but it is a common misconception. Try running the code I suggested you run, and read the docs I suggested you read to see why. To be more clear, try running this - [false].any? and [false].empty? and see if you get what you expect.