Ruby Style Guide compliance

I've adapted code to a Ruby Style Guide without any changes in core logic. 
I've made it to understand it's ins and outs, improving the code quality by the way.

If you dont like something please feel free to point out improper places — and I'll make all the necessary fixes.

PS. You're welcome to examine the correctness of the code in your project cases. It's highly likely of me to make some stupid and obvious mistakes.