3 ms·
why return false unless a.bytesize == b.bytesize instead of if a.bytesize != b.bytesize return false disclaimer: never programmed in ruby
by patates 11y ago
why
return false unless a.bytesize == b.bytesize
instead of
if a.bytesize != b.bytesize
return false
disclaimer: never programmed in ruby
- edu 11y agoIt's idiomatic ruby. First as the conditional only has one statment it's preferred to write it in its shorthand way, so instead of if a.bytesize != b.bytesize return false We start by writing return false if a.bytesize != b.bytesize And then unless is the negated conditional, so we rewrite it as return false unless a.bytesize == b.bytesize Which some peolpe (myself included) consider easier to read, the 'unless' is easier to note (more chars) than the '!='.