Ruby console prints an array


puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp

words = text.split(" ")

words.each do |word|
  if word != redact
    print word + " "
    print "REDACTED "

Hello, why does the Ruby console print an array at the end of the looping ? As I know, Ruby console prints the last statement and the words variable is not at the last statement. Why ?

Text to search through:
billy halim
Word to redact:
billy REDACTED ["billy", "halim"]



As you will learn later on BillyHalim, ruby always "returns" the last variable to be declared. In this case, the last variable you have declared is the array words, and so it returns that to the console.

Barry Allen


Thanks for letting me know that the most accurate is Ruby console returns the last variable


Maybe reading the =Book=