Skip to content
loading...

re: Real applications of flip-flop in ruby VIEW POST

FULL DISCUSSION
 

Nicely done, Mudsie! I especially like the code you provide, which makes the definition unambiguous. You might elaborate "...it is treated as flip-flop only inside conditionals and ternary operator." by pointing out that it would otherwise be parsed as a range. Also, in your print example, consider also showing the effect of print i if i.odd?..i.odd?.

 

Hi Cary, nice to see you here!

I did not elaborate “it’s treated as ff inside conditionals only” mostly because it’s written everywhere in docs and I’d like the reader who’s indeed curious to go read docs instead of / after this luring intro.

Also, if the reader does not go REPL to play with it, trying if i.odd?..i.odd? and if i.odd?...i.odd? and all that, this writing is not for that reader :)

 

I suggested showing if i.odd?..i.odd? as well as if i.odd?..i.even? because several descriptions of the operator (including Bekal's) don't cover the case where the switch-on condition is the same as the switch-off condition.

code of conduct - report abuse