Struct :symbol vs 'string' difference

(Yukihiro Matsumoto) #1



In message “Struct :symbol vs ‘string’ difference” on 02/06/06, Tim Sutherland writes:

ruby 1.6.6 (2001-12-26) [i586-linux]

Bar =‘Bar’, :a, :b, :c), 2, 3) -> #<Struct::Bar a=1, b=2, c=3>

Foo =, :a, :b, :c), 2, 3) -> #

I’m wondering why there is this difference, which I found surprising.

If the first argument to the “new” is a string, it will be the name of
the Struct class (as in Struct::Bar). It’s by the historical reason.
Ruby did not allow unnamed class before.