Skip to content

Commit a61cad1

Browse files
committed
Add examples for the no optional hash params rule
1 parent be438f8 commit a61cad1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

README.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6259,6 +6259,21 @@ Write `ruby -w` safe code.
62596259
Avoid hashes as optional parameters.
62606260
Does the method do too much? (Object initializers are exceptions for this rule).
62616261

6262+
[source,ruby]
6263+
----
6264+
# bad
6265+
def send_email(subject, opts = {})
6266+
to = opts[:to]
6267+
cc = opts[:cc]
6268+
# ...
6269+
end
6270+
6271+
# good
6272+
def send_email(subject, to:, cc: nil)
6273+
# ...
6274+
end
6275+
----
6276+
62626277
=== Instance Vars [[instance-vars]]
62636278

62646279
Use module instance variables instead of global variables.

0 commit comments

Comments
 (0)