Ruby编辑不打印

时间:2013-04-24 20:53:21

标签: ruby each

我正在通过Codecademy课程来熟悉Ruby的基础知识,但是我发现了他们的编辑!行使。我发布了我认为应该做的伎俩,但它拒绝打印。

练习说明如下:

让我们开始简单:编写一个.each循环,通过单词并打印出它找到的每个单词。

如果可以,请帮忙。谢谢!这是我的代码:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
  end

1 个答案:

答案 0 :(得分:1)

我按以下方式运行:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
end

<强> 输出:

What is your text, bra?
i anm
What is being hidden?
Good
i anm

见这里:

codeacadamy