I have an exercise where I have to make a program to program an email list from 1 to 50 in this format "[email protected]"
I have tried several methods, and I think I have found the right one, but it only converts the numbers. In the result obtained in the terminal I get the email address and the numbers in the array from 1 to 50. I would like this to display the mails 1 by 1 with the numbers changing, thank you in advance.
a = (1..50).to_a
puts "jean.dupont.#{a}@email.fr"
CodePudding user response:
To display the emails one by one you can iterate over the range
or array
(using each
) and interpolate each number in the email address
(1..50).each { |n| puts "jean.dupont.#{n}@email.fr" }
=> [email protected]
=> [email protected]
=> [email protected]
=> [email protected]
=> [email protected]
=> ...