Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRubyobject model classes are objectsSingle-choice MCQ

A class instance variable set in the class body is not shared with subclasses. With the code below, `Counter.count` is `1` but `SubCounter.count` is `nil`. Why does the subclass not see the value?

class Counter @count = 0 class << self attr_accessor :count end end Counter.count += 1 class SubCounter < Counter; end Counter.count # => 1 SubCounter.count # => nil