# Refactorings again: idea for library

**URL:** <https://www.ruby-forum.com/t/refactorings-again-idea-for-library/115582>\
**Category:** Ruby\
**Created:** [September 26, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/refactorings-again-idea-for-library/115582 "2007-09-26T15:42:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [September 26, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/refactorings-again-idea-for-library/115582/1 "2007-09-26T15:42:56Z")

</div>

Hi all.

Here’s an idea stolen from [1] and [2].

Suppose we have a library. Suppose we’ve done some refactorings in it  
(method or class renamed, class splitted into several, or joined, or…)

The task: change all client code in correspondence to library change.

The trick:

## library/changelog.rb

## module MyLibrary::Changelog version(0.2.5) do method\_renamed [SomeClass, :method\_a] =\> :method\_b method\_removed [SomeClass, :old\_method], “he was too old” module\_method\_moved [SomeModule, :method\_c] =\> OtherModule class\_renamed ClassA =\> ClassB end end

in code, which uses our library:

* * *

require ‘library’  
require ‘library/changelog’ #can omit this if you’re not interested in  
changes

s = SomeClass.new

s.method\_a  
#prints "Warning: method #method\_a is renamed to #method\_b. Called from  
app.rb:10  
#then calls s.method\_b

s.old\_method  
#throws “Error: #old\_method was removed because he was too old”  
#? or prints warning and DOESN’T calls any method

SomeModule::method\_c  
#prints "Warning: method #method\_c moved to OtherModule. Called from  
app.rb:12  
#then calls OtherModule::method\_c

## ClassA.new #prints “Warning: ClassA renamed to ClassB. blah” #then calls ClassB.new

the version(0.0.2) in example above can allow user to say  
MyLibrary::ChangeLog.from\_version = 0.2.1 #migrating from 0.2.1 to 0.2.5

and see only appropriate warnings.

Wha?

V.

1:  
[http://www.dogbiscuit.org/mdub/weblog/Tech/Programming/Ruby/RubyMethodRename](http://www.dogbiscuit.org/mdub/weblog/Tech/Programming/Ruby/RubyMethodRename)  
d  
2: [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/49730](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/49730)

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [September 26, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/refactorings-again-idea-for-library/115582/2 "2007-09-26T16:35:13Z")

</div>

On Sep 26, 6:42 am, “Victor "Zverok" Shepelev”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> s.method\_a  
> app.rb:12  
> and see only appropriate warnings.
> 
> Wha?

It a very interesting idea. But I fear it would too hard to maintain  
for anything but the smallest lib/app. I think it’s better to just to  
have intermediary versions that add warnings to methods that are going  
away soon (if possible).

T.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [September 26, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/refactorings-again-idea-for-library/115582/3 "2007-09-26T16:42:49Z")

</div>

From: Trans [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
Sent: Wednesday, September 26, 2007 5:34 PM

> > ```
> > module_method_moved [SomeModule, :method_c] => OtherModule
> > 
> > ```
> 
> have intermediary versions that add warnings to methods that are going  
> away soon (if possible).

Hmmm…

1. I think, many library authors already put this information to  
changelogs  
in human-readable form (like “Warning! API changed: blah”). I just  
propose  
to do such messages auto-checkable.

2. I’ve envisioned (but forget to show) the case you saying about:

module MyLibrary::Changelog  
version(0.2.5) do  
method\_deprecated [SomeClass, :method\_a], “Will remove this ASAP”  
end  
end

just one more usage of the idea 🙂

V.
