From: Tony Mobily Date: 2006-02-20T19:05:34+09:00 Subject: Class variables and Constants Hello people, what is the actual difference between class variables and constants? If I write: ------------------------------------------ #!/usr/local/bin/ruby -w class TonyCantCode @@internal=10 def TonyCantCode::something return @@internal end def TonyCantCode::something=(what) @@internal=what end end class TonyReallyCantCode Something=20 end p TonyCantCode::something p TonyReallyCantCode::Something TonyCantCode::something=30 TonyReallyCantCode::Something=40 p TonyCantCode::something p TonyReallyCantCode::Something ------------------------------------------------ I get a warning about changing a constant, PLUS I called the method TonyCantCode::something so that I didn't have to use the brackets at the end. BUT... as far the the scope is concerned, they do seem to be very. very similar. As far as I can see: * Constants would be referenced mainly from the OUTSIDE of the class. For example, if TonyReallycantCode::Something was something very meaningful to the USERS of TonyReallyCantCode. * Class variables would be used mainly from WITHIN the class. Yes, it is possible to create accessors, but they might not be necessary. This is what I worked out. Now the question is: is all the above correct? BYE! Merc.