Fixes #2578, check that `installed` isn't empty

The underlying issue in #2578 is when a formula is `keg_only`, but not
installed, we're sending `#last` to an empty Array, which returns
`nil`, and causes the `NoMethodError` reported in #2578 and in the
homebrew cookbook issue. This should also resolve that issue:

https://github.com/opscode-cookbooks/homebrew/issues/53