Skip to content

Instantly share code, notes, and snippets.

@adhusson
Created November 12, 2009 05:52
Show Gist options
  • Save adhusson/232637 to your computer and use it in GitHub Desktop.
Save adhusson/232637 to your computer and use it in GitHub Desktop.
def try(x,bad_value, &block)
val = block.call
if val == bad_value
return (x <= 0) ? nil : try(x-1) { block.call }
else
return val
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment