You don't need to return explicitly!
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
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,}
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.