views:

36

answers:

2

I am going through a video tutorial that was using Rails 2.3, and they did:

<%= first_array = ['a', 'b', 'c'] %>

When they did that, the output they got was:

abc

When I am trying to follow along, on my setup (Rails 3.0), I get:

["a", "b", "c"]

Is this difference normal or did I do something incorrectly?

Thanks.

A: 

I don't know for sure, but I would guess this is a difference between versions of ruby rather than differences between versions of rails.

sosborn
Ahh I see. Interesting. You could be right, but would love confirmation :)
marcamillion
Samuel provided a great explanation for this so please accept his answer :)
sosborn
+5  A: 

Rails doesn't display arrays differently between 2 and 3. But between ruby 1.8 and 1.9 it has changed.

In ruby 1.8 to_s returns self.join which joins all of the elements together without a separator.
In ruby 1.9 to_s is an alias for inspect which returns the array as "[#{self.join(', ')}]" (roughty speaking).

Samuel