Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > deprecated

Reply
Thread Tools

deprecated

 
 
Robert Klemme
Guest
Posts: n/a
 
      02-25-2008

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
 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      02-25-2008
Robert Klemme wrote:
>
> 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


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

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      02-26-2008
On 25.02.2008 23:02, Joel VanderWerf wrote:
> Robert Klemme wrote:
>> 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

>
> 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


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

Kind regards

robert
 
Reply With Quote
 
Stéphane Wirtel
Guest
Posts: n/a
 
      02-26-2008
Thanks for this code :d
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deprecated methods: how important to fix? kaeli Java 3 08-24-2004 08:20 PM
XML/JDOM: Replacement for deprecated XMLOutputter ?? Bernd Oninger Java 1 06-10-2004 06:50 PM
deprecated getResources method David McDivitt Java 2 05-19-2004 01:49 PM
deprecated servlet session management: getSessionContext(); david Java 4 10-09-2003 12:22 AM
Deprecated warnings within deprecated code Barney Barumba Java 0 07-23-2003 12:46 AM



Advertisments