In most cases where you would use a C# or Java enum, Symbols are
better than Strings. Can't say for sure what would be better without
knowing what you are using it for.
> > On Thu, Jan 27, 2011 at 9:31 PM, Alistair Holt <
alistairh...@gmail.com>wrote:
>
> >> Thanks Khaja. It looks like it's mainly down to personal preference. Is
> >> there really an advantage to using Symbols over Strings in finite sets of
> >> values when you can specify validates_inclusion :something, :in => xxx for
> >> both?
>
> >> --
> >> Alistair
>
> >> On Jan 27, 2011, at 4:44, Khaja Minhajuddin <
minhajud...@cosmicvent.com>
> >> wrote:
>
> >> You should use a Symbol whenever a field can have a value from a finite
> >> set of values. e.g. If you are planning to store the "role" of a "user", it
> >> could be a symbol ( :admin, :customer, etc, ). FWIW Mongoid stores this as a
> >> "string" in mongodb as mongodb doesn't have any special datatype for
> >> Symbols. Mongoid transparently converts it from a String to Symbol while
> >> loading it and vice versa while saving it. So, it's only a symbol when
> >> loaded in your rails/ruby app, that means you get all the advantages of
> >> using symbols only in the rails/ruby context. This question on stackoverflow
> >> => <
http://stackoverflow.com/questions/2415780/why-dont-more-projects-use...>
> >>
http://stackoverflow.com/questions/2415780/why-dont-more-projects-use...shows
> >> a few advantages of using Symbols.
>
> >> Regards
> >> Khaja Minhajuddin
> >> <
http://cosmicvent.com/>
http://cosmicvent.com