嗨,尝试将另一个元素添加到数组,但它不断出现在ruby上的错误

时间:2016-07-20 16:59:33

标签: ruby-on-rails

def take_a_number (array,element)
 array.push element
 puts "Welcome, #{element}. You are #{} in line."


end
1)德利计数器#take_a_number没有人在线应该添加一个人 线路     失败/错误:take_a_number(katz_deli,“Ada”)

  #<IO:<STDOUT>> received :puts with unexpected arguments                  
    expected: ("Welcome, Ada. You are number 1 in line.")                  
         got: ("Welcome, Ada. You are  in line.")                          
# ./deli_counter.rb:21:in `puts'                                           
# ./deli_counter.rb:21:in `take_a_number'                                  
# ./spec/deli_counter_spec.rb:28:in `block (4 levels) in <top (required)>'

2 个答案:

答案 0 :(得分:1)

Welcome, #{element}. You are **#{}** in line.

您需要传递#{} 中的值,目前将返回/置空,因此您的测试失败的原因。 因此,传递array.length,array.size或甚至array.count将解决您的问题

例如

Welcome, #{element}. You are #{array.length} in line.

答案 1 :(得分:0)

对于您的测试,您需要添加字符串插值中最后一个元素的位置。也许是这样的。

def take_a_number(array, element)
  array.push(element)
  puts "Welcome, #{element}. You are #{array.size} in line."
end