On Sat, Sep 27, 2008 at 9:55 AM, w wg <duzuike / gmail.com> wrote:
> I have noticed that Number elements and String elements of an array
> generate diffrent results in its EACH method if you change the
> elements.  But it is difficult to understand how ruby implements
> arrays each method block.
>

They are treated the same way.
Try this:
a = [1, 2, 3, 4, 5]
a.each {|x| x + 1}
puts a

b = ["1", "2", "3", "4", "5"]
b.each {|x| x + "1"}
puts b

Array#each has nothing to say about changing each element. It's about
difference between "+" and "<<" methods. "+" just create new object
and doesn't change original objects. "<<" for String object changes
object from left side. There is also "<<" for integers but it works
different and doesn't change objects because of fact that integers are
immutable in Ruby.

-- 
Radosw Bu„Šat

http://radarek.jogger.pl - m blog