10 Mar
Ruby’s stacked conditionals – who knew?
puts "hello readers" if you_are_a_reader if you_can_read unless you_already_read_it
I was playing around with some project euler code I'm working on (anyone else figure out the Pencils of Rays with code that executes in less than a minute??). Anyway - I was going through my code and adding "if debug" to the end of all my puts statements b/c I didn't want to see them for the next run through. So by mistake, I blindly added "if debug" at the end of 'puts "odd" if odd', giving me 'puts "odd" if odd if debug'. Neat. Then, going through trying to find the bottlenecks, I noticed it. So jumped into irb to make sure it was legit and it was.
Interesting. Not sure where I'd ever use it, though.