Hi --

On Fri, 11 Oct 2002, William Djaja Tjokroaminata wrote:

> Kontra, Gergely <kgergely / mlabdial.hit.bme.hu> wrote:
> >>> - the ||= operator exists :-)
> > But not for class variables...
>
> Hi,
>
> I am sorry that I don't understand what you meant.  I am using ruby 1.6.7
> (2002-03-01) [i686-linux]:
>
> # -------------------------------------------
> class MyClass
> 	def initialize
> 		data = false
> 		data ||= true
> 		puts data	# >> true
> 		@data = false
> 		@data ||= true
> 		puts @data	# >> true
> 		@@data = false
> 		@@data ||= true
> 		puts @@data	# >> true
> 	end
> end
> MyClass.new
> # -------------------------------------------
>
> It seems that the ||= operator works for local, instance, and class
> variables.

Yes, if the class var is already initialized.  However (1.6.7):

  candle:~$ ruby -ve 'a ||= 3; @a ||= 3; @@a ||= 3'
  ruby 1.6.7 (2002-03-01) [i686-linux]
  -e:1: uninitialized class variable @@a in Object (NameError)

I seem to be between 1.7 installations, so I can't test it...  but I
believe that's what Gergely meant.


David

-- 
David Alan Black                      | Register for RubyConf 2002!
home: dblack / candle.superlink.net     | November 1-3
work: blackdav / shu.edu                | Seattle, WA, USA
Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com