Created
May 13, 2015 12:28
-
-
Save Bodacious/a8e25c0de9f1494c8673 to your computer and use it in GitHub Desktop.
When you should nest multiple conditionals in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def should_nest_multiple_conditionals? | |
| x = rand(10).to_i | |
| if Time.now.strftime("%A") != "Friday" | |
| if current_client.is_large_faceless_conglomerate? | |
| return true | |
| elsif Time.now.strftime("%A") == "Friday" | |
| return true | |
| end | |
| elsif LocalWeather.new("Edinburgh").sunny? | |
| if Armageddon.about_to_happen? | |
| return true | |
| elsif x > 5 | |
| return true if x <= 5 | |
| end | |
| else | |
| raise "Y U nest code like dis?" | |
| end | |
| end | |
| # Could be refactored to... | |
| def should_nest_multiple_conditionals? | |
| false | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment