Nitpicking "if" structure

So what would be better?

def method
if !event
return nil
end
return Table.find_first_by_name("oak")
end
def method
return nil unless event
return Table.find_first_by_name("oak")
end
def method
return !event ? nil : Table.find_first_by_name("oak")
end

I figured the first is a bit clearer, but longer…and while the third is shorter, I’m not sure that a coverage tool would flag parts of it as uncovered. And the second…well, having two returns seem kinda ugly. What do you think?

Advertisements

One thought on “Nitpicking "if" structure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s