0

わかりました、私は codeacademy ルビー トラックを行っていますが、問題を抱えていません。今は動作させることができますが、なぜ動作するのかわかりません。運動のための指示:

簡単に始めましょう: 単語を通過する .each ループを書き、見つかった単語を出力するだけです。

問題が機能する理由を理解するために問題をいくつかのステップに分けましたが、非常に混乱しています。問題の私のコードは次のとおりです。

puts "Text to search through: " #ask user for input
text = gets.chomp
#store the user's input into the variable text
puts "Text to be reducted: " 
#ask the user for input
redact = gets.chomp 
#store the user's input into the variable redact

words = text.split(" ") 
=begin
split the user's input into the variable words
store that input into the variable words
=end
words.each do |word| 
=begin
creates a placeholder for the user's input
then attach an expression to the input stored in
the variable words one at a time. The variable
words holds the value of the variable text
=end
    if word != redact 
=begin
if word (which now holds the value of words that's
stored in the variable text, and which is the user's input)
is not equal to the value of the variable redact do something
=end
        word = word + " "
=begin
increment the value of word by an empty space
why do I need to increment the value of word by an empty space? 
=end
        print "#{word}" #print the value of the variable word
else
    print "REDACTED" #otherwise, print the value redacted
end
end

プログラムは、スペースで区切られた文字列を使用し、変更した場合にのみ機能します

word = word + ""

それ以外の

word = word + " "

誰かが私のためにそれを段階的に分解してくれれば、本当に感謝しています.

より視覚的に説明するために、ビデオを作成しました。ここにリンクがあります:ルビー編集ビデオ

ありがとうございました。

4

2 に答える 2

0

ビデオの問題は、"nelson" が "nelson " と同じではないことです。Codeacademy のスコアでは、単語を印刷する前にスペースを追加しても一致しません。

于 2013-08-25T22:24:19.180 に答える