June 2017
Beginner
330 pages
7h 30m
English
In addition to regular splat arguments that are essentially flexible containers for arguments, Ruby also allows for keyword-based splat arguments. You can think about this tool as a cross between splat and keyword arguments.
Extending our baseball roster method, let's imagine that we need to give it the ability to print out the full list of players and positions. By leveraging keyword-based splat arguments, we can accomplish this feature. The following is the code for this feature:
def roster **players_with_positions players_with_positions.each do |player, position| puts "Player: #{player}" puts "Position: #{position}" puts "\n" end end data = { "Altuve": "2nd Base", "Alex Bregman": "3rd Base", "Evan Gattis": ...Read now
Unlock full access