14. Becoming More Selective


Add your code below!

movie_ratings = {
  memento: 3,
  primer: 3.5,
  the_matrix: 5,
  truman_show: 4,
  red_dawn: 1.5,
  skyfall: 4,
  alex_cross: 2,
  uhf: 1,
  lion_king: 3.5
# Add your code below!
good_movies = movie_ratings.select do |m, r|
    r > 3

Why is it m and r? How is this relevant to the code?


It could be any name, but m and r are fitting. m => movie, r => rating.

The two are block variables in the scope of the block, and act as placeholders as select iterates over the hash. m is the key, r is the value.


so you can just put random letters?


Thank You for your assistance


Yes, though random and arbitrary are two different things. Arbitrary is usually chosen for the sake of readability. Just randomly applying variable names can be messy and difficult to read (when aiming for relevant meaning).

Variable names that describle what they reference add meaning to code. It's always easier to understand code if we can identify objects and their purpose.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.