Permalink
Browse files

Supplement guide by mentioning Struct.new

  • Loading branch information...
1 parent ce73aaa commit 3efca0f431015c2596dc22c0867dae3c59125613 @marcandre committed Apr 7, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 README.md
View
18 README.md
@@ -707,6 +707,24 @@ mutators.
end
end
```
+* Consider using `Struct.new`, which defines the trivial accessors,
+onstructor and comparison operators for you.
+
+ ```Ruby
+ # good
+ class Person
+ attr_reader :first_name, :last_name
+
+ def initialize(first_name, last_name)
+ @first_name = first_name
+ @last_name = last_name
+ end
+ end
+
+ # better
+ class Person < Struct.new (:first_name, :last_name)
+ end
+ ````
* Consider adding factory methods to provide additional sensible ways
to create instances of a particular class.

0 comments on commit 3efca0f

Please sign in to comment.