On 10/15/06, dblack / wobblini.net <dblack / wobblini.net> wrote:

> On Mon, 16 Oct 2006, Rick DeNatale wrote:

> > 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.

Except that there isn't a one-one relationship between equal valued
strings and integers.   In that sense symbols really are strings with
special characteristics.


> > 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.

Well, Matz has already answered this one better than I could.

In any event, this change SHOULD be less controversial than the fact
that as of the current 1.9, Strings are no longer enumerable!

$ irb1.9
irb(main):001:0> "abc\ndef\n".sort
NoMethodError: undefined method `sort' for "abc\ndef\n":String
        from (irb):1:in `Kernel#binding'

irb(main):004:0> sm = String.instance_methods; nil
=> nil
irb(main):005:0> Enumerable.instance_methods.sort.reject {|m| sm.include?(m)}
=> [:all?, :any?, :collect, :detect, :each_cons, :each_slice,
:each_with_index, :entries, :enum_cons, :enum_slice, :enum_with_index,
:find, :find_all, :find_index, :first, :grep, :group_by, :inject,
:map, :max, :max_by, :member?, :min, :min_by, :none?, :one?, :reject,
:select, :sort, :sort_by, :to_a, :zip]
irb(main):006:0> Enumerable.instance_methods.sort.select {|m| sm.include?(m)}
=> [:count, :include?, :partition]
irb(main):007:0>

There are some methods which can produce enumerators from a string,
(:bytes, :each_byte, :each_line, :lines). But removing Enumerable from
String seems to be a significant change.

Also there's no :chars, or :each_char, although "abc"[0] now gives
"a" instead of 97.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/