Use 'super' and add custom arguments to a specific class

Sometimes we want to create a parent class that will be shared for children classes, nevertheless, in some of the children classes we need additional arguments that will be only specific for that class and we don't need them in the parent class, to avoid adding additional arguments that won't be relevant to the parent class, we can do the next:

class ParentClass
  attr_reader :user

  def initialize(user)
    @user = user
class ChildOne < ParentClass
  attr_reader :token

  def initialize(user, token)
    @token = token

This way the new variable token will be available only for the ChildOne class.

Learned by samantha-bello on Nov 12, 2021