June 2017
Beginner
330 pages
7h 30m
English
Additionally, Ruby gives us the ability to name our arguments. This can be helpful when you have method signatures with a number of arguments and you want the method calls to be explicit. Here is how you can use named arguments in Ruby:
def print_address city:, state:, zip: puts city puts state puts zip end print_address city: "Scottsdale", state: "AZ", zip: "85251"
If you run this code, it will work properly.

So why are named arguments helpful? I think the easiest way to answer that question is to update our code and remove the named components. That code would look like this:
def print_address city, state, zip puts city ...
Read now
Unlock full access