Skip to content

Commit

Permalink
Add rule about not extending Data.define
Browse files Browse the repository at this point in the history
See also:
* [PR adding new cop for this rule](rubocop/rubocop#11728)
* [Original issue](rubocop/rubocop#11696)
  • Loading branch information
Karol Topolski committed Mar 26, 2023
1 parent 7e54062 commit dceb7bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3604,6 +3604,21 @@ end
Person = Struct.new(:first_name, :last_name)
----

=== Don't Extend `Data.define` [[no-extend-data-define]]

Don't extend an instance initialized by `Data.define`.
Extending it introduces a superfluous class level and may also introduce weird errors if the file is required multiple times.

[source,ruby]
----
# bad
class Person < Data.define(:first_name, :last_name)
end
# good
Person = Data.define(:first_name, :last_name)
----

=== Duck Typing [[duck-typing]]

Prefer https://en.wikipedia.org/wiki/Duck_typing[duck-typing] over inheritance.
Expand Down

0 comments on commit dceb7bb

Please sign in to comment.