Skip to content

Commit 1d3c77a

Browse files
committed
Slightly improve no-extend-struct-new wording and add code example
1 parent e19d1d6 commit 1d3c77a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,11 +2301,20 @@ condition](#safe-assignment-in-condition).
23012301
````
23022302

23032303
* <a name="no-extend-struct-new"></a>
2304-
Don't extend a `Struct.new` - it already is a new class. Extending it
2305-
introduces a superfluous class level and may also introduce weird errors if
2306-
the file is required multiple times.
2304+
Don't extend an instance initialized by `Struct.new`. Extending it introduces
2305+
a superfluous class level and may also introduce weird errors if the file is
2306+
required multiple times.
23072307
<sup>[[link](#no-extend-struct-new)]</sup>
23082308

2309+
```Ruby
2310+
# bad
2311+
class Person < Struct.new(:first_name, :last_name)
2312+
end
2313+
2314+
# good
2315+
Person = Struct.new(:first_name, :last_name)
2316+
````
2317+
23092318
* <a name="factory-methods"></a>
23102319
Consider adding factory methods to provide additional sensible ways to
23112320
create instances of a particular class.

0 commit comments

Comments
 (0)