ga-wdi-boston / ruby-object-class-methods

Other
0 stars 130 forks source link

@@cats_count in cat_counter.rb #20

Closed raq929 closed 7 years ago

raq929 commented 7 years ago

The linter doesn't like this. It thinks I should replace the class var with a class instance var. But I'm teaching class vars.

I don't like having linter errors, but I'm not sure how to avoid this one. Ideas?

raq929 commented 7 years ago

Possibly related to #19?

jrhorn424 commented 7 years ago

Use a class instance var? What's your objection? No need to do it this time.

jrhorn424 commented 7 years ago

You're correct. The whole example should be waxed per #19. But to illustrate my previous comment:

class Cat
-  @@cats_count = 0
+  @cats_count = 0

  def initialize(name)
    @name = name
-    @@cats_count += 1
+    @cats_count += 1
+    # or maybe self.instance_variable_get(:@cats_count) += 1
  end

  def self.cats_count
-    @@cats_count
+    @cats_count
+    # or maybe self.instance_variable_get(:@cats_count)
  end

  def meow
    puts "#{@name} meows"
  end
end
jrhorn424 commented 7 years ago

I see cat_counter.rb is gone. Is this closeable, @raq929?

jrhorn424 commented 7 years ago

https://www.commandercoriander.net/blog/2013/05/08/a-note-on-class-variables/

MicFin commented 7 years ago

cat_counter.rb is gone and there are no class variables in repo @@. This can be closed @jrhorn424.

gaand commented 7 years ago

\o/

Also, yay!