我有很多下面的关系
belongs_to :breed
belongs_to :category
belongs_to :color
belongs_to :country
belongs_to :city
belongs_to :user
我把它折叠成
[:breed, :category, :color, :country, :city, :user].each { |r| belongs_to r }
问题是:有没有可能像那样崩溃
[:breed, :category, :color, :country, :city, :user].belongs_to
以及如何编写这样的代码
或者类似的东西
[:breed, :category, :color, :country, :city, :user].each &:belongs_to
或者更优雅的
您仍然可以使用符号数组来改进您的解决方案。但除了我理解简洁简洁的意愿之外,请注意,这样的解决方案将阻止您将任何选项传递给belongs_to
。。。并且具有多个belongs_to
没有代码气味