I am new to Ruby and I wrote a very simple application to print the days of week and then delete one day in a loop:
def print_days(days)
days.each do |day|
print "The day of the week is: #{day}\n"
days.delete(day)
print "\n*****************************************************\n"
print days
print "\n*****************************************************\n"
end
end
wd = %w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
print print_days(wd
This gives the following output when run. Can anyone explain me why Tuesday, Thursday and Saturday are skipped when I am deleting each element sequentially and the array shows them being there? You can run this simple code at your setup:
The day of the week is: Monday
*****************************************************
["Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
*****************************************************
The day of the week is: Wednesday
*****************************************************
["Tuesday", "Thursday", "Friday", "Saturday", "Sunday"]
*****************************************************
The day of the week is: Friday
*****************************************************
["Tuesday", "Thursday", "Saturday", "Sunday"]
*****************************************************
The day of the week is: Sunday
*****************************************************
["Tuesday", "Thursday", "Saturday"]
*****************************************************
["Tuesday", "Thursday", "Saturday"]
deleteinsideeach? what you are trying to achieve?