尽量用
detect
而不是find
。find
容易和 ActiveRecord 的find
搞混 -detect
则是明确的说明了
是要操作 Ruby 的集合, 而不是 ActiveRecord 对象。
[link]尽量用
reduce
而不是inject
。
[link]尽量用数组和 hash 字面量来创建,
而不是用 new。 除非你需要传参数。
[link]为了可读性倾向于用 而不是
Array# *
。
[link]# 错误
%w(one two three) * ', '
# => 'one, two, three'
%w(one two three).join(', ')
# => 'one, two, three'
如果可以的话, 用普通的 symbol 而不是字符串 symbol。[link]
# 错误
:"symbol"
:symbol
-
hash = {
:protocol => 'https',
:only_path => false,
:controller => :users,
:action => :set_password,
:redirect => ,
}