From: sto.mar@... Date: 2013-03-25T05:53:56+09:00 Subject: Re: Writing a game, trying to make dynamic loops Am 24.03.2013 21:06, schrieb Daniel Ferguson: > puts "How many players?" > players = Array.new(gets.to_i) #.to_i converts the string to an integer if possible ... > n = 1 > players.map! { |e| > puts "Name of player #{n}?" > e = Player.new(gets.chomp()) #chomp strips off the newline character > } The assignment to `e' doesn't have any effect. The above could be simpler written as: puts "How many players?" players = Array.new(gets.to_i) n = 1 players.map! { puts "Name of player #{n}?" n += 1 # missing Player.new(gets.chomp) } BUT: map! isn't really needed here: the old array elements are all `nil' and not used at all. Also, using a separate `n' to count through the players is redundant. To me a more natural solution would be something like this: puts "How many players?" number_of_players = gets.to_i players = [] 1.upto(number_of_players) do |n| puts "Name of player #{n}?" players << Player.new(gets.chomp) end or maybe: puts "How many players?" number_of_players = gets.to_i players = (1..number_of_players).map do |n| puts "Name of player #{n}?" Player.new(gets.chomp) end --