Minor plugin.rb refactor

Hello!

I saw some duplicated code in plugin.rb and tried to refactor it. I'm not sure if this is correct (although the tests seem to pass) or useful (I'll leave that to the maintainer/community to decide). But I think it might help a little bit.

This basically took two pieces of code that looked quite duplicated and tried to break them into a single function. I'm iocor on freenode if you'd like to chat about the patches.

Thanks
Sam Phippen