Code Snippet – Avoid Class Variables

Avoid Class Variables class Locomotive @@examples = ["Flying Scotsman", "Big Boy"] def self.examples = @@examples end class ElectricLocomotive < Locomotive @@examples = ["GG1"] end Locomotive.examples # => ["GG1"] Ruby class (@@) variables have surprising semantics, and are "community-deprecated". There are better alternatives!

Responses