Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Question: Why does the hash show when I do not include a finish "print_seperator"?

Hi, so after this video, I tried making my own version of the grocery list, with a word collector.

It works, but if I remove the last "puts print_separator", the result is:

Dutch word: Hoi
Spanish word: Ola
Finished? (y/n)y

--------------------------------------------------------------------------------
    Dutch word: Hoi     Spanish word: Ola
{"Hoi"=>"Ola"}

Why is this?

See code:

def ask_words
    @word_combi = Hash.new
    done = ""

      until done == "y"
        print "Dutch word: "
        dutch_word = gets.chomp

        print "Spanish word: "
        spanish_word = gets.chomp

        @word_combi.store( dutch_word, spanish_word )

        print "Finished? (y/n)"
        done = gets.chomp
      end

  end

  def print_separator(character="-")
    print character * 80
  end

  def print_list
    puts print_separator
    @word_combi.each do |dutch, spanish|
      puts "\tDutch word: " + "#{dutch}" + "\t\t" + "Spanish word: " + "#{spanish}"
    end
    puts print_separator
  end

  puts ask_words()
  puts print_list()