From: Hugh Sasse Staff Elec Eng Date: 2000-03-17T14:51:22+00:00 Subject: [ruby-talk:01975] Re: Enumerations and all that. On 17 Mar 2000, Dave Thomas wrote: > 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). :-) Ok, I stand corrected. > > > > 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. > Oh, I see. > > > Regards > > Dave > Thanks, Hugh hgs@dmu.ac.uk