Sha256: dd3b67821a28f692cebe5b1e98226ca29b7a346f99fc75de4d3b9f5cf2e267f7
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
# Class Variable ## Introduction Class variables form part of the global runtime state, and as such make it easy for one part of the system to accidentally or inadvertently depend on another part of the system. So the system becomes more prone to problems where changing something over here breaks something over there. In particular, class variables can make it hard to set up tests (because the context of the test includes all global state). For a detailed explanation, check out [this article](http://4thmouse.com/index.php/2011/03/20/why-class-variables-in-ruby-are-a-bad-idea/) ## Example Given ```Ruby class Dummy @@class_variable = :whatever end ``` Reek would emit the following warning: ``` reek test.rb test.rb -- 1 warning: [2]:Dummy declares the class variable @@class_variable (ClassVariable) ``` ## Getting rid of the smell You can use class-instance variable to mitigate the problem (as also suggested in the linked article above): ```Ruby class Dummy @class_variable = :whatever end ``` ## Configuration _Class Variable_ supports the [Basic Smell Options](Basic-Smell-Options.md).
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reek-4.0.3 | docs/Class-Variable.md |
reek-4.0.2 | docs/Class-Variable.md |