Like% w [text] in Ruby, not including \ n where it wraps the lines

I want to build an array of state abbreviation lists, and since it is long, I want to split it into several lines. However, using% w or% W includes \ 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", like "SD"be"SD\n"

How to solve this problem?

+5
source share
2 answers

Just strip the slashes and there will be no new string characters or slashes

+15
source
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"]
+1
source

All Articles