Reputation: 25
I'm coming from a python background and I can't figure out why I'm getting the error message. I can't find where I'm not ending any of my loops. This works if I don't have everything into functions.
namelist = ["eric","lena","austin","booger"]
counter = 0
names = Hash.new
def start()
puts "enter name"
print "> "
input = $stdin.gets.chomp
namelist.push(input)
more_names()
hash_portion()
end
def more_names()
puts "press 1 to add another name otherwise press 2 if you're done"
print "> "
choice = $stdin.gets.chomp
if choice == 1
puts "> "
input1 = $stdin.gets.chomp
namelist.push(input1)
more_names()
elsif choice == 2
nil
else
more_names()
end
end
def hash_portion()
until counter == namelist.length do
n_namelist = namelist.sample(1000000000000)
n_namelist.each do |n|
counter += 1
names ["#{counter}"] = "#{n}"
end
end
names.each do |digit,person|
puts "#{digit}. #{person}"
end
end
start()
Upvotes: 0
Views: 38
Reputation: 106792
Remove the whitespace in this line:
names ["#{counter}"] = "#{n}"
Must look like this:
names["#{counter}"] = "#{n}"
Upvotes: 1