Skip to content

Commit

Permalink
keyword arguments for boolean arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ruba-ruba committed Nov 24, 2015
1 parent 4ad66f7 commit 84fe73d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,30 @@ Translations of the guide are available in the following languages:
some_method('w', 'x', 'y', 'z') # => 'w, x, y, z'
```
* <a name="keyword_arguments"></a>
Use keyword arguments or options hash when passing boolean argument to method.
```Ruby
# bad
def some_method(bar = false)
puts bar
end
# good (ruby <= 1.9.x)
def some_method(options = {})
bar = options.fetch(:bar, false)
puts bar
end
# good (ruby >= 2.0)
def some_method(bar: false)
puts bar
end
some_method # => false
some_method(bar: true) # => true
```
* <a name="parallel-assignment"></a>
Avoid the use of parallel assignment for defining variables. Parallel
assignment is allowed when it is the return of a method call, used with
Expand Down

0 comments on commit 84fe73d

Please sign in to comment.