A Refactoring thing ...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

A Refactoring thing ...

Dennis smith-4
I have a number of cases where I have to methods that do the same thing
and I want to get rid of one of them and change all references to be the
other one.

I tried to rename the method I want to get rid of but it would not let me.
I then tried to temporarily delete the other method, but there are quite
a few
cases of that method in other classes.

Is there really a reason that the RB won't let me rename method "x" to "y"
just because "y" already exists??

--
Dennis Smith                        [hidden email]
Cherniak Software Development Corporation       +1 905.771.7011
400-10 Commerce Valley Dr E                Fax: +1 905.771.6288
Thornhill, ON Canada L3T 7N7    http://www.CherniakSoftware.com

Reply | Threaded
Open this post in threaded view
|

Re: A Refactoring thing ...

Reinout Heeck-2
Dennis Smith wrote:
> I have a number of cases where I have to methods that do the same thing
> and I want to get rid of one of them and change all references to be the
> other one.
>
> I tried to rename the method I want to get rid of but it would not let me.
> I then tried to temporarily delete the other method, but there are quite
> a few
> cases of that method in other classes.

That is what I usually do: remove the method with the desired new name
(don't use 'save remove' but just plain 'remove'), then rename the
method with the old name to the new name.

If both methods do exactly the same this should work (provided your
application is idle while the crucial method is absent)

>
> Is there really a reason that the RB won't let me rename method "x" to "y"
> just because "y" already exists??
>

You could enhance 'rename' so if the target already exists AND is the
same code you can proceed with the refactoring.

'Extract method' already has such a test (it will suggest a method with
the same semantics if it already exists), so look there for inspiration ;-)



R
-