rubymonk示例的指导

rubymonk示例的指导,ruby,Ruby,关于rubymonk的研究 有一个问题提出如下: def string_length_interpolater(incoming_string) "The string you just gave me has a length of " end 这个问题的解决办法是: def string_length_interpolater(incoming_string) "The string you just gave me has a length of #{incoming_

关于rubymonk的研究

有一个问题提出如下:

def string_length_interpolater(incoming_string)   
   "The string you just gave me has a length of " 
end
这个问题的解决办法是:

def string_length_interpolater(incoming_string)
  "The string you just gave me has a length of #{incoming_string.length}"
end
然后它输出这个答案: 输出窗口

标准:

interpolates 2 when I pass 'Hi' ✔
interpolates 4 when I pass 'Good' ✔
我不明白这个答案是怎么给出的,因为我在字符串的任何地方都看不到Hi或Good这个词


如果您能帮助我们理解,我们将不胜感激。我在这里是一个完全的新手,所以请对我放松。

RubyMonk服务器正在为您的变量传入字符串传递这些值。验证这一点的一个简单测试是将
输入的\u字符串添加到上方或下方

"The string you just gave me has a length of "

当您点击run时,您将看到传入字符串的值作为输出。

我不理解您刚才写的内容,这有点让我不知所措。你能给我解释一下为什么在任何代码中都不存在“hi”和“good”这两个词的2和4吗?RubyMonk在其他地方有一个脚本,它会检查你编写的脚本,以确保它做了正确的事情。在这种情况下,它是通过给(或“传入”)string_length_interpolator方法两个不同的字符串:“Hi”和“Good”来实现的。然后检查“Hi”的长度是否为2,“Good”的长度是否为4。谢谢tom,这对我来说更有意义,但为什么rubymonk对这一点的理解如此模糊?它的输出方式使得代码似乎给出了错误的答案。。。或者我只是对ruby失去了理解