# Deprecated

**URL:** <https://www.ruby-forum.com/t/deprecated/186771>\
**Category:** Ruby\
**Created:** [February 25, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/deprecated/186771 "2008-02-25T22:26:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robkuz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@robkuz](https://www.ruby-forum.com/u/robkuz)\
**Post date:** [February 25, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/deprecated/186771/1 "2008-02-25T22:26:58Z")

</div>

This just occurred to me (for Java fans):

class Module  
def deprecated \*meths  
meths.each do |me|  
aliased = “_deprecate_#{me}”  
alias\_method aliased, me  
class\_eval “def #{me}(\*a,&b) $stderr.puts ‘WARNING: deprecated  
method called: #{me}’; #{aliased}(\*a,&b) end”  
end  
end  
end

irb(main):010:0\> class String  
irb(main):011:1\> deprecated :to\_i  
irb(main):012:1\> end  
=\> [:to\_i]  
irb(main):013:0\> “123”.to\_i  
WARNING: deprecated method called: to\_i  
=\> 123  
irb(main):014:0\>

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![robkuz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@robkuz](https://www.ruby-forum.com/u/robkuz)\
**Post date:** [February 25, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/deprecated/186771/2 "2008-02-25T23:03:33Z")

</div>

Robert K. wrote:

> ```
> end
> 
> ```
> 
> end  
> end

Nice (and I’m not a Java fan). I’d make the output indirect, though, in  
case of GUI etc. Also, you could use this to only warn on the first call  
of each method for a given class.

class Module  
def deprecated \*meths  
meths.each do |me|  
aliased = “_deprecate_#{me}”  
alias\_method aliased, me  
class\_eval %{  
def #{me}(\*a,&b)  
warn\_deprecated(’#{me}’)  
#{aliased}(\*a,&b)  
end  
}  
end  
end  
end

class Object  
def warn\_deprecated me  
warn “WARNING: deprecated method called: #{me}”  
end  
end

---

<div class="post-metadata">

**Author:** ![robkuz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/34f0e0/32.png) [@robkuz](https://www.ruby-forum.com/u/robkuz)\
**Post date:** [February 26, 2008, 8:46am UTC](https://www.ruby-forum.com/t/deprecated/186771/3 "2008-02-26T08:46:07Z")

</div>

On 25.02.2008 23:02, Joel VanderWerf wrote:

> > ```
> > end
> > 
> > ```
> 
> ```
> aliased = "_deprecate_#{me}"
> 
> ```
> 
> class Object  
> def warn\_deprecated me  
> warn “WARNING: deprecated method called: #{me}”  
> end  
> end

Good idea! This could even be combined with standard logging libs.

Kind regards

robert
