Practice
-
What numbers will the following code output?
[1,2,3,4,5].each { |num| puts num if num.odd? } -
What would this each method output from this string?
"ThisdmakesdmoredsensedwithoutdD's".split("d").each { |letter| puts letter }
Note: We are method chaining in the above example. The string is being split into smaller separate strings at the parameter passed in. Then the each method is called on that array.
-
What does select do for this hash?
food = { "apple" => "fruit", "carrot" => "vegetable", "tomato" => "fruit" } food.select do |item, category| category == "vegetable" end
-
What will map do?
numbers = [1,2,3,4,5] numbers.map { |num| num * 5 }
-
Now what is the value of numbers?