Reputation: 13
I have a list of addresses and want to flag if they are American or Canadian. I have a list of US states and CA Providences. Is there a more ruby-like way to do this:
us = false
address = '1234 Fake Address Ave N, Funtown, TX, 59595'
address = address.split(' ')
address.each do |part|
if USStates.include? part
us = true
end
end
Upvotes: 0
Views: 74
Reputation: 13
us = false
address.each { |part| us = true if USStates.include? parts }
Upvotes: 1
Reputation: 4656
Here is a one liner
address = '1234 Fake Address Ave N, Funtown, TX, 59595'
us = USStates.any? { |state| address.include?(state) }
Upvotes: 3