|
|
# Coding Conventions |
|
# Coding Conventions
|
|
\ No newline at end of file |
|
|
|
|
|
## Do not use _Class Instance Variables_
|
|
|
|
|
|
|
|
They are not doing what one would expect and they violate the [Liskov Principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle)
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
[136] pry(File):1> class A
|
|
|
|
[136] pry(File):1* cattr_accessor :a
|
|
|
|
[136] pry(File):1* end
|
|
|
|
=> [:a]
|
|
|
|
[137] pry(File):1> class B < A
|
|
|
|
[137] pry(File):1* cattr_accessor :a
|
|
|
|
[137] pry(File):1* end
|
|
|
|
=> [:a]
|
|
|
|
[138] pry(File):1> class C < A
|
|
|
|
[138] pry(File):1* cattr_accessor :a
|
|
|
|
[138] pry(File):1* end
|
|
|
|
=> [:a]
|
|
|
|
[139] pry(File):1> C.a
|
|
|
|
=> nil
|
|
|
|
[140] pry(File):1> A.a = 42
|
|
|
|
=> 42
|
|
|
|
[141] pry(File):1> C.a
|
|
|
|
=> 42
|
|
|
|
[142] pry(File):1> A.a
|
|
|
|
=> 42
|
|
|
|
[143] pry(File):1> B.a
|
|
|
|
=> 42
|
|
|
|
[144] pry(File):1> B.a = 84
|
|
|
|
=> 84
|
|
|
|
[145] pry(File):1> A.a
|
|
|
|
=> 84
|
|
|
|
[146] pry(File):1> C.a
|
|
|
|
=> 84
|
|
|
|
[147] pry(File):1>
|
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
\ No newline at end of file |