• 尽量用 detect 而不是 findfind
    容易和 ActiveRecord 的 find 搞混 - detect 则是明确的说明了
    是要操作 Ruby 的集合, 而不是 ActiveRecord 对象。
    [link]

  • 尽量用 reduce 而不是 inject
    [link]

  • 尽量用数组和 hash 字面量来创建,
    而不是用 new。 除非你需要传参数。
    [link]

  • 为了可读性倾向于用 而不是 Array# *
    [link]

    1. # 错误
    2. %w(one two three) * ', '
    3. # => 'one, two, three'
    4. %w(one two three).join(', ')
    5. # => 'one, two, three'
  • 如果可以的话, 用普通的 symbol 而不是字符串 symbol。[link]

    1. # 错误
    2. :"symbol"
    3. :symbol
    1. hash = {
    2. :protocol => 'https',
    3. :only_path => false,
    4. :controller => :users,
    5. :action => :set_password,
    6. :redirect => ,
    7. }