Skip to content

Instantly share code, notes, and snippets.

@r38y
Created October 20, 2012 21:01
Show Gist options
  • Save r38y/3924791 to your computer and use it in GitHub Desktop.
Save r38y/3924791 to your computer and use it in GitHub Desktop.
class Checking
def run
Rails.logger.info "Checking #{snitch.id} (#{snitch.name})..."
unless checkable?
Rails.logger.error "Snitch #{snitch.id} is not checkable"
return false
end
... more stuff
end
end
# how do I exit early from Checking#run from another method?
class Checking
def run
Rails.logger.info "Checking #{snitch.id} (#{snitch.name})..."
handle_non_checkable
... more stuff
end
private
def handle_non_checkable
unless checkable?
Rails.logger.error "Snitch #{snitch.id} is not checkable"
return false
end
end
end
@adamvduke
Copy link

Make handle_non_checkable return true in the case that checkable? returns true, and make run return false unless handle_non_checkable.
Not exactly what you wanted, but close maybe? https://gist.github.com/3925821

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