literal icon indicating copy to clipboard operation
literal copied to clipboard

How to forward arguments to parent class?

Open binarygit opened this issue 1 year ago • 1 comments

I'm using the dry-initializer gem (trying to switch to literal) and have things setup this way:

class ParentClass
  option :collapsable, default: proc { false }
  option :collapsed, default: proc { false }
  option :icon, optional: true
end

class ChildClass < ParentClass
  option :label
end

With dry-initializer, any extra options passed to the child class are automatically forwarded to the parent class. So, ChildClass.new(label: '..', collapsable: '...', ...) is similar to calling super within the initialize method of the ChildClass. Is there a similar way to do this with literal?

I read the README and there's no mention of anything like this. Does this mean, I can't used literal in this situation?

binarygit avatar Aug 15 '24 06:08 binarygit

We use literal this way across our codebase and don't have any issues. It's a bit confusing with positional arguments but otherwise works great.

hangsu avatar Aug 15 '24 14:08 hangsu

How this works at the moment is instead of passing arguments to the super initialzer, the sub initializer just inherits all the properties defined on the super class.

joeldrapper avatar Aug 27 '24 18:08 joeldrapper