Can multiple objects be inserted with the << operator in Rails 3.1?
问题 Could I write the following ... raw_data.categories.each do |category| obj.categories << category end As the following instead? ... obj.categories << raw_data.categories 回答1: obj.categories |= raw_data.categories 回答2: Take a look at Array#<< and Array#push . Array#<< takes one which is appended in place to given array. For example: irb> array = %w[ a b c ] # => ["a", "b", "c"] irb> array << 'd' # => ["a", "b", "c", "d"] however, if you pass an array, you'll be surprised at the result irb>