File tree Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -308,44 +308,43 @@ end
308
308
Use the Ruby 1.9 syntax for hash literals when all the keys are symbols:
309
309
310
310
``` ruby
311
- # good
312
- user = {
313
- login: " defunkt" ,
314
- name: " Chris Wanstrath"
315
- }
316
-
317
311
# bad
318
312
user = {
319
313
:login => " defunkt" ,
320
314
:name => " Chris Wanstrath"
321
315
}
322
316
317
+ # good
318
+ user = {
319
+ login: " defunkt" ,
320
+ name: " Chris Wanstrath"
321
+ }
323
322
```
324
323
325
324
Use the 1.9 syntax when calling a method with Hash options arguments or named arguments:
326
325
327
326
``` ruby
328
- # good
329
- user = User .create(login: " jane" )
330
- link_to(" Account" , controller: " users" , action: " show" , id: user)
331
-
332
327
# bad
333
328
user = User .create(:login => " jane" )
334
329
link_to(" Account" , :controller => " users" , :action => " show" , :id => user)
330
+
331
+ # good
332
+ user = User .create(login: " jane" )
333
+ link_to(" Account" , controller: " users" , action: " show" , id: user)
335
334
```
336
335
337
336
If you have a hash with mixed key types, use the legacy hashrocket style to avoid mixing styles within the same hash:
338
337
339
338
``` ruby
340
- # good
339
+ # bad
341
340
hsh = {
342
- : user_id => 55 ,
341
+ user_id: 55 ,
343
342
" followers-count" => 1000
344
343
}
345
344
346
- # bad
345
+ # good
347
346
hsh = {
348
- user_id: 55 ,
347
+ :user_id => 55 ,
349
348
" followers-count" => 1000
350
349
}
351
350
```
You can’t perform that action at this time.
0 commit comments