Finished, but help required not related to the tasks!


#1

Hi,

So i've done the tasks, but now trying to clean things up, including making user input's convert to downcase, so they can write in capital and the case statments will still work and sorting the display of all the films in alphabetical order (see below).
Anyway, I want to know how to get the films being displayed, come out displayed without _ and instead with actual spaces, as in: The Breakfast Club instead of The_Breakfast_Club

Thanks

movies = {
    DK: 10,
    Harry_Potter: 10,
    Departed: 8,
    The_Breakfast_Club: 7,
}

    when "display"
        movies.sort.each {|title, rating| puts "#{title}: #{rating}"}


#2

@satty10
Compiled from the found articles with google search
ruby replace underscore site:stackoverflow.com
http://stackoverflow.com/questions/7547065/how-to-safely-replace-all-whitespaces-with-underscores-with-ruby
ruby sorting a hash by key ascending site:stackoverflow.com
http://stackoverflow.com/questions/4339553/sort-hash-by-key-return-hash-in-ruby

movies.sort.map{|k,v|
#
     puts "#{k.downcase.split('_').join(' ')} #{v}"
}

#3

Thanks for the response, I tried the way you wrote it and the way the people in the first link was saying, but just keep getting errors.


#4

@satty10,
could you give us the EXACT error you are getting......
and
to start, remove the comma-,
in your movies-dictionary from the line
The_Breakfast_Club: 7


#5

The movies in your hash are currently symbols.

Try changing it to strings right before you puts and then using the .include? and .gsub! method. :slight_smile: