DEV Community

Discussion on: If Ruby’s so Happy, What’s %w(a b c)

Collapse
 
jamesncox profile image
James Cox

I remember in early stages of learning Ruby being annoyed be these too, asking myself “Why would I want to use this??”.

And honestly, I think they’re pretty cool, but I still don’t quite understand when you should use these over just writing the array itself.

I’d love to know the appropriate/optimal use cases!

Collapse
 
cooljasonmelton profile image
Jason Melton

From what I've read, the main reason they exist is to give more readability and brevity. Seems the point is less commas and quotes. That being said, I've never made a habit of using them.

When I wrote this, I was thinking: more options means better, but in all honesty, I rarely take advantage of a lot of Ruby's alternatives. For example, I've never once used "detect" though I've used "find" a ton.

I tend to stick with what whatever I learn initially unless there's a good reason to change. Rethinking it now, I think I'm back to not liking the shorthand, lol.