7

I've seen plenty of posts providing the -W0 flag as an answer to this issue, but I don't want to suppress all warnings, just warnings of a particular value.

I'm running a non-rails app (which uses ActiveRecord, notwithstanding) on Ruby 1.8.7. I want to keep all warnings except for the following DEPRECATION WARNING:

Object#id will be deprecated; use Object#object_id

If that's not possible, I'd like to jettison all deprecation warnings. Java, at least, lets you do this. How about Ruby?

Update: I've upvoted both answers but checked the one that later searchers will expect to find here.

4
  • 1
    Why don't you just stop using Object#id? Commented Jul 31, 2011 at 17:17
  • 1
    Is changing the method call to #object_id unfeasible? Commented Jul 31, 2011 at 17:17
  • Not going to work. The object in mind is an ActiveRecord instance, so I'm actually looking for the ActiveRecord attribute 'id'. Commented Jul 31, 2011 at 18:49
  • Similar question: stackoverflow.com/questions/608713/… Commented Nov 17, 2011 at 22:53

2 Answers 2

10

If there's a specific section of code that produces the warnings, you could try mixing in the Kernel module from ActiveSupport and wrap it with a silence_warnings block (example pulled straight from the RDoc):

silence_warnings do value = do_something_that_causes_warning # no warning voiced end noisy_call # warning voiced 

Is it absolutely necessary to suppress it? It's not like you're compiling something and have to sift through a ton of warnings all at once...

Sign up to request clarification or add additional context in comments.

4 Comments

I'm not compiling, indeed, but I do like to have a clean log because I have resorted to my log files many a time.
Fair point. I'm still interested why changing the method name is difficult especially as it returns the same value as the original. Is this some kind of legacy application? Dependency you can't modify / test?
Using object_id is a no-go because I'm not looking for the object_id, rather, I'm looking for the value of the attribute 'id'. The object in mind is an instance of ActiveRecord.
I've never read about the ActiveRecord Kernel. Can you give me some material to help me understand your recommendation above? (the object in question subclasses ActiveRecord already; when I make use of it outside of Rails, however, I get the warning I mentioned above).
4

Edit: If you use read_attribute(:id), then you should avoid the waring. Thanks Jeremy!

I'm not a Rails developer, but isn't there a method that allows you to say "I want the database field id, not the id method of the object"?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.