From: Dave Thomas Date: 2000-03-17T08:45:23-06:00 Subject: [ruby-talk:01972] Re: Enumerations and all that. Hugh Sasse Staff Elec Eng writes: > > s = Spigot.new > > > > s.color = :red > > s.size = :large > > > > p s.color > > p s.size > > This can only be done for classes which have been given the enum method. > Also, this 'looks' like encapsulation is being broken, because s.color is > not a method call, but accessing something inside s. That's in accordance with Meyer's uniform access principle, and a pretty common idiom. The important thing is that the implementation allows you to change the setter method transparently to the user. As these is never any direct access to instance variables, there's never any cases of broken encapsulation in Ruby when you see a.b = c (unless the class designer chose to break encapsulation, that is). > > Anyway, here's all the code. It works under 1.5, but I'm not sure if > > the new Symbol stuff means it doesn't work under 1.4. > > Not sure what you mean here, the only "unusual" thing is the id2name > but that is in the 1.4 manual. In Ruby 1.5.3, :fred returns an object of class Symbol, not a Fixnum. Regards Dave