0

I have this code:

require '/octokit'
require '/csv'
CSV.open("node_attributes.csv", "wb") do |csv|
  csv << [Octokit.user "rubinius"]
  csv << [Octokit.user "sferik"]
  # add one more request for each piece of information needed
end

However, it would be smoother if I could have it iterate through a list and call the Octokit.user command for every name on the list, e.g.

list = ["rubinius, "sferik"]

How can I convert my clunky function into a nice iterator that goes through the list?

histelheim
  • 4,938
  • 6
  • 33
  • 63

2 Answers2

2

Try this:

require '/octokit'
require '/csv'
CSV.open("node_attributes.csv", "wb") do |csv|
  users = ["rubinius", "sferik"]
  users.each do |u|
    csv << [Octokit.user(u)]
  end
end
Linuxios
  • 34,849
  • 13
  • 91
  • 116
1

Inside your block do this:

list.each {|item| csv << [Octokit.user item]}
Max
  • 1,468
  • 10
  • 16