Skip to content

Commit

Permalink
Merge pull request rubocop#93 from marcandre/struct
Browse files Browse the repository at this point in the history
Struct.new
  • Loading branch information
bbatsov committed Apr 8, 2012
2 parents f9e8dd6 + 3efca0f commit 04b60d8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Expand Up @@ -607,8 +607,8 @@ syntax.
counter += 1 # increments counter by one
```

* Keep existing comments up-to-date. No comment is better than an outdated
comment.
* Keep existing comments up-to-date. An outdated is worse than no comment
at all.
* Avoid writing comments to explain bad code. Refactor the code to
make it self-explanatory. (Do or do not - there is no try.)

Expand Down 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 04b60d8

Please sign in to comment.