Eureka's answer is good, but here is just a brief explanation to figure out what is going on.
map returns a new array with the results of block execution once for each element of the array. When you write [s.name, s.id] unless s.name == "excluded_state" , this forces the block to return nil when s.name == "excluded_state" that is, the result will be something like
[["NY", 1], nil, ["CA", 2]]
So, you can use reject to remove the unwanted state first, or simply use compact 1 to remove the nil entry as a result of your map , since you originally wrote it.
Array#compact returns a copy of the array with all nil elements removed.
mikej
source share