From: dblack@... Date: 2006-10-16T09:56:31+09:00 Subject: Re: Symbol < String in Ruby > 1.8 Hi -- On Mon, 16 Oct 2006, Rick DeNatale wrote: > On 10/15/06, dblack@wobblini.net wrote: >> Hi -- >> >> I'm wondering if someone could summarize for me the rationale for >> making Symbol a subclass of String in 1.9. I understand that symbols >> and strings both represent text, and have certain characteristics in >> common, but I always thought of symbols as an internally used data >> type that Ruby exposes, essentially unchanged, for our use. It's hard >> to adjust to thinking of them as string descendants. >> >> I guess my instinct would be to have a module -- TextLike, or >> something -- that both String and Symbol mixed in, rather than have >> Symbol be a subclass of String. > > I guess that for one thing it's that there really isn't much harm in > it. In 1.9 Symbols seem to act as frozen strings. You can't mutate > them but otherwise they act as strings. > > And it's pretty common to convert between strings and symbols either > way. Rails seems to do it a lot, and it does things to make them > interchangeable in a lot of contexts. True, but that's also true of strings and integers. > The one thing the change does is to obsolete old explanations about > how Symbols aren't strings. In 1.9 they ARE strings, but they are > frozen and have a fixed mapping between a given string value and the > object_id. I'm still not seeing the problems or gaps in the language that this addresses, but I guess it's pretty much an in-place change. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org