0

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

Tyra
  • 531
  • 1
  • 5
  • 16
  • Not a duplicate, but thanks for the pointers, I will check all these links out. I am just trying to understand why 'each_pair'.. – Tyra Oct 10 '11 at 06:12

1 Answers1

2

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
Kyle d'Oliveira
  • 6,382
  • 1
  • 27
  • 33