DEV Community

Discussion on: Getting Cozy with Ruby

Collapse
 
ben profile image
Ben Halpern

A big love or hate with Ruby are the methods that objects have like...

array = []
array.empty? # true

num = 1
num.zero? # false
num = 0
num.zero? # true

I find it funny when a linter wants me to use .zero? as its so highly specific and odd to me. .positive? seems a bit more natural to me along the same lines.

Rails provides .first, .second, etc. up to .fifth for arrays and collections. In a trolling fashion, it also has .forty_two, which returns the forty-second element.

(1..200).to_a.forty_two # 42
Collapse
 
deciduously profile image
Ben Lovy

Hah! That really does come off like a "screw you yes we did this".

I'm a huge fan of the wide variety of messages you can pass, but it does seem like it will take a while to learn everything that's available. They seem to lead to very readable code.

Collapse
 
tadman profile image
Scott Tadman • Edited

There used to be more of these whereupon there was debate, and ultimately a cull. #forty_two is an artifact of that, if you can call it, process.