O'Reilly logo
  • Lorem Ipsum thinks this is interesting:

subclasses technically do not inherit instance variables;


Cover of Head First Ruby


what does "technically do not inherit instance variables" mean?

``` class Boat def name @name = "skippy" end end

class PowerBoat < Boat #subclass PowerBoat inherits superclass Boat end

pb = PowerBoat.new pb.name => "skippy" ``` Here clearly both the instance methods AND the value of instance variable @name is inherited. I can imagine a scenario where my misunderstanding of this could cause big problems in large projects. When I call .instance_variables on pb it returns and empty array so there seems to be a fine distinction. Maybe .name is a "pointer". I guess a take-away for me is to avoid declaring instance variables within the superclass and only call...