DEV Community

loading...

Discussion on: Redundant 'return' detected - Ruby Programming.

Collapse
databasesponge profile image
MetaDave 🇪🇺

Good investigation!

Idiomatic Ruby often involves an "early return", so it is possible that the following style of code, which avoids a local variable, would also work for you.

def some_function(x)
  return 33 if x.blank?

  if x == 3
    10
  elsif x == 5
    16
  else
    nil
  end
end

An if or unless at the end of a method can often be avoided in this way.