I want to build an array of a list of state abbreviations, and since it is long, I want to split it over several lines. Using %w or %W, however, includes the \n where the lines break.
STATES = %w(AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME\
MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD\
TN TX UT VT VA WA WV WI WY)
So "ME"
will be "ME\n"
, as will "SD"
be "SD\n"
How do I solve this problem?
Just drop the slashes and there will not be any new line characters or slashes
irb(main):003:0* STATES = %w(AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME\
irb(main):004:0] MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD\
irb(main):005:0] TN TX UT VT VA WA WV WI WY).collect(&:chomp)
=> ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With