Skip to content

Commit

Permalink
Supplement guide by mentioning Struct.new
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Apr 7, 2012
1 parent ce73aaa commit 3efca0f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down

0 comments on commit 3efca0f

Please sign in to comment.