I am creating a week-by-week report of meetings using Ruby. I have a large array that contains the names of the meetings, and I have multiple instances of each element based on how many weeks they occured.
Simplified example I am starting with:
meetingsArray = ["boardInvestorsMeeting", "clientMeeting", "clientMeeting", "clientMeeting", "waterCoolerChat", "waterCoolerChat", "waterCoolerChat", "waterCoolerChat"]
My attempt:
meetingsArray = ["boardInvestorsMeeting", "clientMeeting", "clientMeeting", "clientMeeting", "waterCoolerChat", "waterCoolerChat", "waterCoolerChat", "waterCoolerChat"]
for m in meetingsArray[m.to_i]
if (meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 1] && meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 2] && meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 3])
puts "Week of the 1st: " + "#{meetingsArray[m.to_i].inject{|a| a}}"
elsif (meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 1] && meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 2])
puts "Week of the 8th: " + "#{meetingsArray[m.to_i].inject{|a| a}}"
elsif (meetingsArray[m.to_i] === meetingsArray[(m.to_i) + 1])
puts "Week of the 15th: " + "#{meetingsArray[m.to_i].inject{|a| a}}"
else
puts "Week of the 22nd: " + "#{meetingsArray[m.to_i].inject{|a| a}}"
end
end
Console error:
iMac:workspace user1$ ruby loop.rb
loop.rb:3:in `<main>': undefined method `each' for "boardInvestorsMeeting":String (NoMethodError)
Desired results:
Week of the 1st: boardInvestorsMeeting
Week of the 1st: clientMeeting
Week of the 8th: clientMeeting
Week of the 15th: clientMeeting
Week of the 1st: waterCoolerChat
Week of the 8th: waterCoolerChat
Week of the 15th: waterCoolerChat
Week of the 22nd: waterCoolerChat
Note that "clientMeeting" has "Week of the 1st:" then "Week of the 8th:" then "Week of the 15th:" in front of it because is repeated twice; while "boardInvestorsMeeting" only has "Week of the 1st:" in front of it because it isn't repeated and only appears in meetingsArray once.
forcorrectly. Please edit your question to include the code that produces the results you say you're getting.ifstatement inside to justputsthemeetingsArrayI get no errors.