【发布时间】:2018-06-06 22:06:26
【问题描述】:
给定一个字母数组:
@recipients_list = ["Mum and Dad", "my best friend", "Brother"]
# > Here are the letters available to ship, select one by number
# > 1. Mum and Dad
# > 2. My best friend
# > 3. Brother
然后我作为用户输入 3(请注意,在这种情况下,Brother 是收件人姓名)。我的代码:
x = @recipient_list.each_with_index do |value, i|
index_start = i + 1
puts "#{index_start}.#{value}"
end
input = gets.chomp.to_i
puts x.at(input)
当用户按 3 时如何从数组中获取兄弟值?有人可以帮忙吗?
【问题讨论】: