When I was building my final Flatiron project, a web app with a React/Redux front-end and a Rails API, I found myself struggling with the data returned from Zillow’s API via fetch
. I was used to using the json()
method to parse API returns into neat, easy-to-use JSON, but quickly realized that wouldn’t work with XML, the only format that Zillow’s API returns.
According to Ruby-Doc.org, arrays are “ordered, integer-indexed collections of any object.” An array can be a collection of strings, integers, etc., and the array syntax is the elements of an array arranged between square brackets, separated by commas:
Pry is an excellent debugging tool when working in Ruby. It allows you to stop your code at a certain point that you set so that you can then check variable values, operations, etc. Think of it as allowing you to go under the hood and check what your code is doing as it runs.
The for
loop is a simple way to iterate over each element of an array. The following code will console.log
each element in array
.
As a Flatiron School technical coach, I often see students confused about what Ruby method arguments are and how they can be used. Students have a tendency to want to hard-code, often using data that they’ve found in their test files, rather than using and operating on arguments. For example: