1

Ruby 2.5 deprecated the Data class and we have three classes in Rails that are named after Data::. This gave us deprecation warnings every time this runs. What's the best way to handle such deprecation? Should we rename our class or is there a better solution?

Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
wwang
  • 59
  • 3
  • The Data class has been deprecated for a long time. Maybe you're confusing it with "Top-level constant look-up"? – Sebastián Palma Jun 16 '20 at 14:13
  • You could silence the errors, but I'd recommend renaming it to something more descriptive. Your usage of the class must be a bit odd, anyway. – Tom Lord Jun 16 '20 at 14:48
  • Since `Data` is a class, not a module, all of your class definitions must look like this: `class Data::Foo; ...; end`, or this: `class Data; class Foo; ...; end; end`. but normally when name-spacing a class in ruby, you should be using modules - e.g. `module UserData; class Foo; ...; end; end`. – Tom Lord Jun 16 '20 at 14:50
  • The `Data` class is likely going to be deleted in ruby version `3.0`, so this deprecation warning should be short-lived regardless. – Tom Lord Jun 16 '20 at 14:51

1 Answers1

0

maybe define your class inside the silence block ?

ActiveSupport::Deprecation.silence do 
   class Data
   end
end

https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Reporting.html#method-i-silence

Joel Blum
  • 7,750
  • 10
  • 41
  • 60