From: Rich Kilmer Date: 2002-09-11T01:31:22+09:00 Subject: RE: Refactoring Ruby This is a multi-part message in MIME format. ------=_NextPart_000_0018_01C258C5.A37B17B0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit How about this: class Foo def [](index) puts "Warning...[] called from #{caller}" get_with_index(index) end def get_with_index(index) #do something different end end As it runs into code that uses the old method the warning will display the file/line# where it was called from. -rich -----Original Message----- From: Steve Tuckner [mailto:STUCKNER@MULTITECH.COM] Sent: Tuesday, September 10, 2002 10:29 AM To: ruby-talk ML Subject: Refactoring Ruby Hi all, I have recently been refactoring some ruby code and was looking for pointers or tips on how best to accomplish it. One problem that I have had is finding all references to methods of a class that I was refactoring. For example, if I have defined: class Foo def[](index) # do something in here end end and I wish to change it to: class Foo def get_with_index(index) # do something slightly different end end How do I find all occurances of in the code where objects of type Foo are doing foo[index]? Searching for [] is no help because that is likely all over the code. There are no type declarations to find instances of foo. I can search for Foo.new and follow it through functions, etc but that is often not simple. Unit tests are helpful to see if my code still works, but even with them I don't feel completely secure that I have caught all instances. Any ideas would be useful. Thanks, Steve Tuckner ------=_NextPart_000_0018_01C258C5.A37B17B0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Message
How=20 about this:
 
class=20 Foo
    def [](index)
        puts "Warning...[] = called from=20 #{caller}"
       =20 get_with_index(index)
    end
    def = get_with_index(index)
        #do something=20 different
    end
end
 
As it=20 runs into code that uses the old method the warning will display the = file/line#=20 where it was called from.
 
-rich
-----Original Message-----
From: = Steve Tuckner=20 [mailto:STUCKNER@MULTITECH.COM]
Sent: Tuesday, September = 10, 2002=20 10:29 AM
To: ruby-talk ML
Subject: Refactoring=20 Ruby

Hi=20 all,
 
I = have recently=20 been refactoring some ruby code and was looking for pointers or tips = on how=20 best to accomplish it. One problem that I have had is finding all = references=20 to methods of a class that I was refactoring. For example, if I have=20 defined:
 
class=20 Foo
    def[](index)
       =20 # do something in here
    end
end
 
and = I wish to=20 change it to:
 
class=20 Foo
    def get_with_index(index)
       =20 # do something slightly = different
    end
end
 
How = do I find all=20 occurances of in the code where objects of type Foo are doing = foo[index]?=20 Searching for [] is no help because that is likely all over the code. = There=20 are no type declarations to find instances of foo. I can search for = Foo.new=20 and follow it through functions, etc but that is often not=20 simple.
 
Unit = tests are=20 helpful to see if my code still works, but even with them I don't feel = completely secure that I have caught all = instances.
 
Any = ideas would be=20 useful.
 
Thanks,
 
Steve=20 Tuckner
------=_NextPart_000_0018_01C258C5.A37B17B0--