Ruby returns the value of the last line executed.

Don't do this:

def foo
  value = Foo.first(:conditions => { :label => "bar" })
  return value
end

Do this instead:

def foo
  Foo.first(:conditions => { :label => "bar" })
end
written by
Craig
published
2009-10-21
Disagree? Found a typo? Got a question?
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.
You can verify that I've written this post by following the verification instructions:
curl -LO http://barkingiguana.com/2009/10/21/you-dont-need-to-return-explicitly.html.orig
curl -LO http://barkingiguana.com/2009/10/21/you-dont-need-to-return-explicitly.html.orig.asc
gpg --verify you-dont-need-to-return-explicitly.html.orig{.asc,}