title: How to get a default value with hashes in ruby
body: <p>I am trying to get a default value whilst using hashes in ruby.  Looking up the documentation you use a fetch method.  So if a hash is not entered then it defaults to a value.  This is my code.</p>
  
  <pre><code>def input_students
    puts "Please enter the names and hobbies of the students plus country of    birth"
    puts "To finish, just hit return three times"
  
    #create the empty array
    students = []
    hobbies = []
    country = []
    cohort = []
  
    # Get the first name
    name = gets.chomp
    hobbies = gets.chomp
    country = gets.chomp
    cohort = gets.chomp
  
    while !name.empty? &amp;&amp; !hobbies.empty? &amp;&amp; !country.empty? &amp;&amp; cohort.fetch(:cohort, january) do #This is to do with entering twice
      students &lt;&lt; {name: name, hobbies: hobbies, country: country, cohort: cohort} #import part of the code.
      puts "Now we have #{students.count} students"
  
      # get another name from the user
      name = gets.chomp
      hobbies = gets.chomp
      country = gets.chomp
      cohort = gets.chomp
    end
    students
  end
  </code></pre>