Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:43:23+00:00 2026-06-06T11:43:23+00:00

I was reading some examples on symbols in ruby, and one example was using

  • 0

I was reading some examples on symbols in ruby, and one example was using a symbol to represent a state name, for example :Montana

However, coming from Java, I would typically use enums here. What I like about enums is that you can group them, so I can do something like:

enum States {
Montana, Minnesota, …
}

And then in the Java code I can call

States.Montana

Is there a logical way to group related symbols in ruby? Would it make sense to create a module containing the symbols? Or is there a more idiomatic way to do this in ruby?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:43:25+00:00Added an answer on June 6, 2026 at 11:43 am

    You would probably want to use modules for this.

    module States
        MN = "Minnesota"
        WI = "Wisconsin"
    end
    
    puts States::MN #=> "Minnesota"
    

    On a side note, “symbol” in Ruby usually refers to the Symbol class which is sort of like an interned string. You write a symbol like :my_symbol. They are often used as keys in HashMaps*.

    *Should be Hash not HashMap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I an reading through some examples of normalization, however I have come across one
Found this is some example CSS I was reading and I'm having a hard
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
When reading a post some points were given without example : To implement IEnumerable
After reading some examples on stackoverflow, and following some of the answers for my
I'm trying to write some microcontroller code using Texas Instruments examples, and it uses
So I have an example I came across in some reading where we define
I'am novice in JS. While reading the book, I found that some examples do
I was reading through some JMockit examples and found this code: final List<OrderItem> actualItems
Running through some examples about sockets, one I've come across is this one and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.