I have an array set up like
%w(Dog Cat Bird Rat).each_with_index do |element, index|
# "w" for word array
# It's a shortcut for arrays
puts ("%-4s + #{index}" % element)
end
This will output something similar like
Dog + 0
Cat + 1
Bird + 2
Rat + 3
What if I want to change the animals to something such as a string? So that it says
This is string 0 + 0
This is string 1 + 1
This is string 2 + 2
etc
Is there a way to do that? This does not work:
%w('This is string 0', 'This is string 1', 'This is string 2', 'This is string 3').each_with_index do |element, index|
# "w" for word array
# It's a shortcut for arrays
puts ("%-4s + #{index}" % element)
end
4.times { |i| puts "This is string #{i} + #{i}" }