Skip to content
Merged
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
23 changes: 23 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,29 @@ def set_x(x) = (@x = x)
def print_foo = puts("foo")
----

=== Ambiguous Endless Method Definitions [[ambiguous-endless-method-defintions]]

Keywords with lower precedence than `=` can appear ambiguous when used after an endless method definition. This includes `and`, `or`, and the modifier forms of `if`, `unless`, `while`, and `until`. In these cases, the code may appear to include these keywords as part of the method body, but instead they actually modify the method definition itself.

In this cases, prefer using a normal method over an endless method.

[source,ruby]
----
# bad
def foo = true if bar

# good - using a non-endless method is more explicit
def foo
true
end if bar

# ok - method body is explicit
def foo = (true if bar)

# ok - method definition is explicit
(def foo = true) if bar
----

=== Double Colons [[double-colons]]

Use `::` only to reference constants (this includes classes and modules) and constructors (like `Array()` or `Nokogiri::HTML()`).
Expand Down