June 2017
Beginner
330 pages
7h 30m
English
You are going to learn how to use the map method with a practical example. Let's imagine that we have an array of strings that represent numbers. This is a common occurrence in Ruby when you work with APIs since they always return values in a string format (even numbers). In cases like these, you may want to convert the values into actual integer data types so that you can use them in your application. This is a great example of how you can leverage the map method. Let's enter this code into the irb session:
["1", "23.0", "0", "4"].map {|x| x.to_i}
In this code, we have an array of strings that represent numbers. To convert each value to its integer equivalent, we're using an x block variable and passing the ...
Read now
Unlock full access