Ruby console prints an array


#1



https://www.codecademy.com/courses/ruby-beginner-en-mzrZ6/0/1?curriculum_id=5059f8619189a5000201fbcb


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 + " "
  else
    print "REDACTED "
  end
end

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:
halim
billy REDACTED ["billy", "halim"]

Thanks


#2

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.

Regards,
Barry Allen


#3

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


#4

@billyhalim
Maybe reading the =Book=
http://docs.ruby-lang.org/en/2.0.0/Array.html
http://docs.ruby-lang.org/en/2.0.0/String.html