Skip to content

Instantly share code, notes, and snippets.

@filipechagas
Created February 19, 2016 14:01
Show Gist options
  • Select an option

  • Save filipechagas/38a1d50039ac8ba03c57 to your computer and use it in GitHub Desktop.

Select an option

Save filipechagas/38a1d50039ac8ba03c57 to your computer and use it in GitHub Desktop.
Cyclomatic Complexity - Guard clause overused
def compute_thing(thing)
if thing[:foo]
update_with_bar(thing)
if thing[:foo][:bar]
partial_compute(thing)
else
re_compute(thing)
end
end
end
def compute_thing(thing)
return unless thing[:foo]
update_with_bar(thing[:foo])
if thing[:foo][:bar]
partial_compute(thing)
else
re_compute(thing) unless thing[:foo][:bar]
end
end
def compute_thing(thing)
return unless thing[:foo]
update_with_bar(thing[:foo])
return re_compute(thing) unless thing[:foo][:bar]
partial_compute(thing)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment