Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Created May 13, 2015 12:28
Show Gist options
  • Select an option

  • Save Bodacious/a8e25c0de9f1494c8673 to your computer and use it in GitHub Desktop.

Select an option

Save Bodacious/a8e25c0de9f1494c8673 to your computer and use it in GitHub Desktop.
When you should nest multiple conditionals in Ruby
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