问题
For example, if I use rename method in mongo ruby driver, I can check the code here
What exactly is happening when I am using map(&:attributes)? I think this means tags.map(&:attributes.to_proc).join(' '), but I am not sure why I am getting "undefined method `each_pair' for Arrayxxxxx" error with this command:
TableA.create(TableB.all.map(&:attributes))
Any insight will be appreciated
回答1:
map returns an array of whatever is returned by the method call.
so
TableB.all.map(&:attributes)
is basically an array of
[TableB.all[0].attributes,TableB.all[1].attributes,TableB.all[2].attributes,...]
Do you want something like
TableB.all.map(&:attributes).each do |attr|
TableA.create(attr)
end
来源:https://stackoverflow.com/questions/7708087/what-is-the-underlying-code-for-tablea-createtableb-all-mapattributes