text
stringlengths 0
444
|
|---|
begin
|
do_something do
|
something
|
end
|
rescue
|
something
|
end
|
true
|
end
|
end
|
# good
|
class Foo
|
def foo
|
begin
|
do_something do
|
something
|
end
|
rescue
|
something
|
end
|
end
|
end
|
----
|
=== Trailing Comma in Method Arguments [[no-trailing-params-comma]]
|
Avoid comma after the last parameter in a method call, especially when the parameters are not on separate lines.
|
[source,ruby]
|
----
|
# bad - easier to move/add/remove parameters, but still not preferred
|
some_method(
|
size,
|
count,
|
color,
|
)
|
# bad
|
some_method(size, count, color, )
|
# good
|
some_method(size, count, color)
|
----
|
=== Spaces around Equals [[spaces-around-equals]]
|
Use spaces around the `=` operator when assigning default values to method parameters:
|
[source,ruby]
|
----
|
# bad
|
def some_method(arg1=:default, arg2=nil, arg3=[])
|
# do something...
|
end
|
# good
|
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
|
# do something...
|
end
|
----
|
While several Ruby books suggest the first style, the second is much more
|
prominent in practice (and arguably a bit more readable).
|
=== Line Continuation in Expressions [[no-trailing-backslash]]
|
Avoid line continuation with `\` where not required.
|
In practice, avoid using line continuations for anything but string concatenation.
|
[source,ruby]
|
----
|
# bad (\ is not needed here)
|
result = 1 - \
|
2
|
# bad (\ is required, but still ugly as hell)
|
result = 1 \
|
- 2
|
# good
|
result = 1 -
|
2
|
long_string = 'First part of the long string' \
|
' and second part of the long string'
|
----
|
=== Multi-line Method Chains [[consistent-multi-line-chains]]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.