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?
You would probably want to use modules for this.
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 inHashMaps*.*Should be
HashnotHashMap.