SHARE
TWEET

Untitled

a guest Feb 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @@y = 1
  2. class MyClass
  3.  @@y = 2
  4. end
  5. p @@y # => 2
  6.    
  7. class Foo
  8.   @@x = 1
  9. end
  10.  
  11. class Bar
  12.   @@x = 2
  13. end
  14.  
  15. Foo.class_variable_get(:@@x) # => 1
  16. Bar.class_variable_get(:@@x) # => 2
  17.    
  18. class Foo
  19.   @@x = 1
  20. end
  21.  
  22. class Bar < Foo
  23.   @@x = 2
  24. end
  25.  
  26. Foo.class_variable_get(:@@x) # => 2
  27. Bar.class_variable_get(:@@x) # => 2
  28.    
  29. @@y = 1
  30. class MyClass
  31.   @@y = 2
  32. end
  33. p @@y
  34.    
  35. @@y = 1
  36.    
  37. @@y = 1
  38. class MyClass
  39.   @@y = 2
  40. end
  41. p @@y
  42. puts MyClass.superclass #=> Object
  43. puts Object.class_variables #=> @@y
  44.    
  45. $y = 1
  46.    
  47. @@y = 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top