Skip to content

Instantly share code, notes, and snippets.

@rdetert
Forked from dblandin/states.rb
Last active March 30, 2023 17:53
Show Gist options
  • Save rdetert/f89cd2b2d52ee423abca to your computer and use it in GitHub Desktop.
Save rdetert/f89cd2b2d52ee423abca to your computer and use it in GitHub Desktop.
Hash of the United States in Ruby
::States = { AK: "Alaska",
AL: "Alabama",
AR: "Arkansas",
AS: "American Samoa",
AZ: "Arizona",
CA: "California",
CO: "Colorado",
CT: "Connecticut",
DC: "District of Columbia",
DE: "Delaware",
FL: "Florida",
GA: "Georgia",
GU: "Guam",
HI: "Hawaii",
IA: "Iowa",
ID: "Idaho",
IL: "Illinois",
IN: "Indiana",
KS: "Kansas",
KY: "Kentucky",
LA: "Louisiana",
MA: "Massachusetts",
MD: "Maryland",
ME: "Maine",
MI: "Michigan",
MN: "Minnesota",
MO: "Missouri",
MS: "Mississippi",
MT: "Montana",
NC: "North Carolina",
ND: "North Dakota",
NE: "Nebraska",
NH: "New Hampshire",
NJ: "New Jersey",
NM: "New Mexico",
NV: "Nevada",
NY: "New York",
OH: "Ohio",
OK: "Oklahoma",
OR: "Oregon",
PA: "Pennsylvania",
PR: "Puerto Rico",
RI: "Rhode Island",
SC: "South Carolina",
SD: "South Dakota",
TN: "Tennessee",
TX: "Texas",
UT: "Utah",
VA: "Virginia",
VI: "Virgin Islands",
VT: "Vermont",
WA: "Washington",
WI: "Wisconsin",
WV: "West Virginia",
WY: "Wyoming"
}
Copy link

ghost commented Jul 24, 2014

Thanks for this. Just a heads up -- there is trailing whitespace on every line.

@macowie
Copy link

macowie commented Aug 6, 2014

Handy! Thanks

@abrambailey
Copy link

No whitespace version. I threw mine in a module in app/helpers so now I can just do ::States.key("Alaska") and get the abbreviation, which helped me! Thanks!

module StatesHelper
::States = {
    AK: "Alaska",
    AL: "Alabama",
    AR: "Arkansas",
    AS: "American Samoa",
    AZ: "Arizona",
    CA: "California",
    CO: "Colorado",
    CT: "Connecticut",
    DC: "District of Columbia",
    DE: "Delaware",
    FL: "Florida",
    GA: "Georgia",
    GU: "Guam",
    HI: "Hawaii",
    IA: "Iowa",
    ID: "Idaho",
    IL: "Illinois",
    IN: "Indiana",
    KS: "Kansas",
    KY: "Kentucky",
    LA: "Louisiana",
    MA: "Massachusetts",
    MD: "Maryland",
    ME: "Maine",
    MI: "Michigan",
    MN: "Minnesota",
    MO: "Missouri",
    MS: "Mississippi",
    MT: "Montana",
    NC: "North Carolina",
    ND: "North Dakota",
    NE: "Nebraska",
    NH: "New Hampshire",
    NJ: "New Jersey",
    NM: "New Mexico",
    NV: "Nevada",
    NY: "New York",
    OH: "Ohio",
    OK: "Oklahoma",
    OR: "Oregon",
    PA: "Pennsylvania",
    PR: "Puerto Rico",
    RI: "Rhode Island",
    SC: "South Carolina",
    SD: "South Dakota",
    TN: "Tennessee",
    TX: "Texas",
    UT: "Utah",
    VA: "Virginia",
    VI: "Virgin Islands",
    VT: "Vermont",
    WA: "Washington",
    WI: "Wisconsin",
    WV: "West Virginia",
    WY: "Wyoming"
}
end

@rdetert
Copy link
Author

rdetert commented Jul 26, 2016

I've removed the trailing whitespaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment