Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions style/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Ruby
* Prefer `if` over `unless`.
* Use `_` for unused block parameters.
* Prefix unused variables or parameters with underscore (`_`).
* Use a leading underscore when defining instance variables for memoization.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Prefer a leading underscore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally lean towards Use, but if others think Preferis more appropriate I can update it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the README:

"Prefer" indicates a better option and its alternative to watch out for.
"Use" is a positive instruction.

Use makes more sense to me, as the alternative is just "don't use an underscore."

* Use `%{}` for single-line strings needing interpolation and double-quotes.
* Use `{...}` for single-line blocks. Use `do..end` for multi-line blocks.
* Use `?` suffix for predicate methods.
Expand Down
4 changes: 4 additions & 0 deletions style/ruby/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def self.class_method
method_body
end

def memoized_method
@_memoized_method ||= 1
end

protected

attr_reader :foo, :user_factory
Expand Down