Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/1062147 to your computer and use it in GitHub Desktop.
Save seivan/1062147 to your computer and use it in GitHub Desktop.
Finding something like `if ( ready? && set? ) { fight! };` in Ruby

Right now, the tagline-code-snippet thing on Codebrawl is if ( ready? && set? ) { fight! };. While this looks nice, this is not valid Ruby code.

So, I'm looking for something better. It should be Ruby, and it should look cool. If you have an idea, please fork the Gist and add it to the list below. Thanks! :)

ready? && set? && fight! 
if ( ready? && set? ) then fight! end
( ready? && set? ) ? fight! : nil


ready! #(raise if not ready)
set!   #(raise if not ready)
fight! #(Will only hit fight if both ready? and set? won't raise an error)

This works if the "ready?" and "set?" method raise exception instead of returning false or nil.

That being said, when competition yell out "ready!" and "set!", they aren't really asking. They are stating. Having ? methods is wrong in this regard. It should be ! and they should raise exception.

ergo

def code_brawl
  ready!
  set!
  fight!
end

Looks the best. I have spoken.

That is all //Seivan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment