Is self.var in a class the same as @@var?

Is this the same?

class Test
  @@class_var= ""
end

class Test
  self.clas_var= ""
end

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Is this the same?

class Test
  @@class_var= ""
end

class Test
  self.clas_var= ""
end

Thanks

--
Posted via http://www.ruby-forum.com/\.

No it is not, as a matter of fact the second idiom is not correct
(even with the typo corrected)...
irb(main):001:0> class Test
irb(main):002:1> @@class_var= ""
irb(main):003:1> end
=> ""
irb(main):004:0>
irb(main):005:0* class Test
irb(main):006:1> self.clas_var= ""
irb(main):007:1> end
NoMethodError: undefined method `clas_var=' for Test:Class
        from (irb):6
irb(main):008:0>

...
I believe that you are looking for accessors to class instance
variables, there are no accessors for class variables

class Test
   @a = 42 ### Class instance variable
   @@b = 42 ### Class variable
   class << self
      attr_accessor :a, :b
      def show
        puts "civar b #{self.b}"
         puts "cvar b#{@@b}"
      end
  end
end

puts Test.a
puts Test.b
Test.b=1
puts Test.b
Test.show

···

On 6/14/07, Emmanuel Oga <emmanuel@lijasdoblea.com> wrote:
        from :0

-------------------
This is a frequent source of confusion at first, so pls keep asking if
I was not very clear :slight_smile:

HTH
Robert
--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw