text stringlengths 0 444 |
|---|
# good |
validates :name, presence: true, length: { within: 1..10 } |
end |
---- |
=== Space in Method Calls [[parens-no-spaces]] |
Do not put a space between a method name and the opening parenthesis. |
[source,ruby] |
---- |
# bad |
puts (x + y) |
# good |
puts(x + y) |
---- |
=== Space in Brackets Access |
Do not put a space between a receiver name and the opening brackets. |
[source,ruby] |
---- |
# bad |
collection [index_or_key] |
# good |
collection[index_or_key] |
---- |
=== Multi-line Arrays Alignment [[align-multiline-arrays]] |
Align the elements of array literals spanning multiple lines. |
[source,ruby] |
---- |
# bad - single indent |
menu_item = %w[Spam Spam Spam Spam Spam Spam Spam Spam |
Baked beans Spam Spam Spam Spam Spam] |
# good |
menu_item = %w[ |
Spam Spam Spam Spam Spam Spam Spam Spam |
Baked beans Spam Spam Spam Spam Spam |
] |
# good |
menu_item = |
%w[Spam Spam Spam Spam Spam Spam Spam Spam |
Baked beans Spam Spam Spam Spam Spam] |
---- |
== Naming Conventions |
[quote, Phil Karlton] |
____ |
The only real difficulties in programming are cache invalidation and naming things. |
____ |
=== English for Identifiers [[english-identifiers]] |
Name identifiers in English. |
[source,ruby] |
---- |
# bad - identifier is a Bulgarian word, using non-ascii (Cyrillic) characters |
заплата = 1_000 |
# bad - identifier is a Bulgarian word, written with Latin letters (instead of Cyrillic) |
zaplata = 1_000 |
# good |
salary = 1_000 |
---- |
=== Snake Case for Symbols, Methods and Variables [[snake-case-symbols-methods-vars]] |
Use `snake_case` for symbols, methods and variables. |
[source,ruby] |
---- |
# bad |
:'some symbol' |
:SomeSymbol |
:someSymbol |
someVar = 5 |
def someMethod |
# some code |
end |
def SomeMethod |
# some code |
end |
# good |
:some_symbol |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.