-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't call super in component constructors
We need to slurp all remaining options in the constructor, so that we can pass them on to the wrapper tag. However, ViewComponent::Base#initialize is defined as def initialize(*); end which messes up keyword argument slurping using the double splat operator. Given the following component constructor def initialize(foo:, **rest) super p rest end I'd expect the behavior to be ThatComponent.new(foo: 1) # {} given that the foo keyword argument is explicitly defined. However the actual behavior is ThatComponent.new(foo: 1) # {:foo => 1} If we don't call super we get the expected behavior: def initialize(foo:, **rest) p rest end ThatComponent.new(foo: 1) # {} However, not calling super is a bit of an anti-pattern (as discussed in rubocop/ruby-style-guide#809), so it would be beneficial to be able to call it still. We cannot get by with slurping unknown keyword arguments before calling super, though: def initialize(foo:, **rest) p rest super p rest end somehow still messes with the local variable: ThatComponent.new(foo: 1) # {} # {:foo => 1}
- Loading branch information
Showing
4 changed files
with
19 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters