From 1d3c77a4ec12981bf7e668682beebdd698390964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mindaugas=20Moz=C5=ABras?= Date: Sun, 18 Jan 2015 22:16:01 +0200 Subject: [PATCH] Slightly improve no-extend-struct-new wording and add code example --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3103266a0..c65a139c5 100644 --- a/README.md +++ b/README.md @@ -2301,11 +2301,20 @@ condition](#safe-assignment-in-condition). ```` * - Don't extend a `Struct.new` - it already is a new class. Extending it - introduces a superfluous class level and may also introduce weird errors if - the file is required multiple times. + Don't extend an instance initialized by `Struct.new`. Extending it introduces + a superfluous class level and may also introduce weird errors if the file is + required multiple times. [[link](#no-extend-struct-new)] + ```Ruby + # bad + class Person < Struct.new(:first_name, :last_name) + end + + # good + Person = Struct.new(:first_name, :last_name) + ```` + * Consider adding factory methods to provide additional sensible ways to create instances of a particular class.