From: Josh Cheek Date: 2012-08-24T21:58:33+09:00 Subject: Re: Would you merge repeating code even when it's get more complex? --001485f6294a62af9004c8028837 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Aug 23, 2012 at 10:34 PM, Martin J. wrote: > Hi, I wrote a module including some instance and class methods with are > very similar. That means some lines do exactly the same once for > instance and once for class methods. I started to refactor theses > methods but the code got quite complex as a result. > > Please take a look at this module: > https://github.com/mjio/uberhook/blob/master/lib/uberhook/base.rb#L43 > > Would you merge these methods to remove the repeating code even when the > code gets more complex and harder to read? > > -- > Posted via http://www.ruby-forum.com/. > > I think the problem here is confusion about object system. I don't see any reason to explicitly handle instance methods and class methods. When you remove this requirement, the duplication goes away. I was going to try refactoring it to show you what I mean, but the tests can't accommodate that, they test implementation instead of behaviour (each method is explicitly tested, so if I don't have those methods doing those exact things, then I'll fail the tests). So instead, I wrote an example from scratch: https://gist.github.com/3450271 --001485f6294a62af9004c8028837 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Aug 23, 2012 at 10:34 PM, Martin J. <lists@ruby-forum.com= > wrote:
Hi, I wrote a module including some instance and class methods with are
very similar. That means some lines do exactly the same once for
instance and once for class methods. I started to refactor theses
methods but the code got quite complex as a result.

Please take a look at this module:
https://github.com/mjio/uberhook/blob/master/lib/u= berhook/base.rb#L43

Would you merge these methods to remove the repeating code even when the code gets more complex and harder to read?

--
Posted via http://= www.ruby-forum.com/.


I think the problem here is confusion = about object system. I don't see any reason to explicitly handle instan= ce methods and class methods. When you remove this requirement, the duplica= tion goes away.

I was going to try refactoring it to show you = what I mean, but the tests can't accommodate that, they test implementa= tion instead of behaviour (each method is explicitly tested, so if I don= 9;t have those methods doing those exact things, then I'll fail the tes= ts). So instead, I wrote an example from scratch: https://gist.github.com/3450271
--001485f6294a62af9004c8028837--