Skip to content
Advertisement

Why am I able to call the class method as if it were an instance method here?

I was looking through this example:

And I was confused as to why it’s ok to call the table_name method in the “self.columns” method as if it were an instance method. Isn’t the “table_name” method a class method? Hence, shouldn’t it be called as “self.class.table_name” in the “self.columns” method as well?

Advertisement

Answer

When inside an abstract class, the self refers to the proper class, not the object. That’s why you can access the method without explicitly telling self

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement