> When I first started learning Ruby, I was excited to discover that Ruby has the keywords and and or as boolean operators. I quickly got into the habit of writing all of my boolean statements with these, instead of the more conventional && and ||, because my code became so much readable pry(main)> a = true && false pry(main)> a = true and false Hmm...I dunno, I don't think the latter is necessarily easier to read th…
a = true and false
is prettier than a = true && false
And if you would actually have read the article and paid close attention you would have learned that the two lines you just said are not functionally equivalent.No ruby programmer would ever have a line that says
a = true and false
It just makes no sense.Maybe a very experienced ninja ruby programmer would, but that programmer would know exactly what he was doing.
The beauty in ruby and in the 'and' keyword is that a ruby programmer intuitively knows when to use which. This article just clears up why exactly they work like you expect them to work.
edit: maybe a weird programmer would do something like this
@message = "We failed :(" and false
at the end of a function that has conditionals with return statements in them.