[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01972] Re: Enumerations and all that.

From: Dave Thomas <Dave@...>
Date: 2000-03-17 14:45:23 UTC
List: ruby-talk #1972
Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> 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

In This Thread