loading...

re: Getting Cozy with Ruby VIEW POST

FULL DISCUSSION
 

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
 

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.

 

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.

code of conduct - report abuse