On Sat, Feb 15, 2003 at 11:02:58AM +0900, Tom Sawyer wrote:
> On Friday 14 February 2003 04:00 pm, Mauricio FernŠŌdez wrote:
> > >   class A
> > >     def initialize
> > >       # local variables
> > >       initialize.a ="instead of just a"
> > >       %b = "as sugar for above (used in blocks)"
> > >       # instance variables
> > >       self.c = "instead of @c"
> > >       d = "as above but where self is implied"
> >
> > How do I use A#c then if there's @c?
> 
> indeed, that actually is intentional. the namespace for variables and methods 
> at the same level (instance or class) is the same. thus:
> 
> 	self.c = 1
> 
> would conflict with:
> 
> 	def c
> 	   1
> 	end

With a warning?
 
> notice what happens though. in either case the result is the same:
> 
> 	puts c  #--> 1
> 
> whether c was defined as an instance variable or an instance method.

so 
  puts c
is 
  puts self.c  # instance variable, not method

Anyway, accessors are broken inside the class' instance methods (and sometimes we want
them, when they do non-trivial things).

Ummm, now I realize that your idea corresponds exactly to defining
automagically accessors for each i.v. .

> > Plus I think locals are more used than i.v. so it makes more sense to
> > prefix the latter...
> 
> the above is the reason why instance varaibles would loose the prefix.

I see, but this doesn't change the fact that I'd have to prefix locals,
which are far more common.

> >
> > >       # class variables
> > >       A.e = "instead of @@e"
> > >       @f = "this then could be class variable sugar"
> >
> > You forgot my beloved class instance variables :)
> >
> > class << A
> >  attr_accessor :e
> > end
> >
> > A.e  # class instance variable, NOT class variable
> 
> technically, these are methods. aren't they?

OK, but there's a name clash anyway :)

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

*** Rince is wagner / schizo.DAINet.de (We have Joey, we have Fun, we have Linux on a Sun)
	-- Seen on #Debian