Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. module A
  2. def A.included(klass)
  3. klass.instance_exec do
  4. @@foo = 0
  5.  
  6. def inc()
  7. puts self.object_id
  8.  
  9. puts @@foo
  10.  
  11. @@foo += 1
  12.  
  13. puts @@foo
  14. end
  15.  
  16. def foo()
  17. puts self.object_id
  18. puts @@foo
  19. end
  20. end
  21. end
  22. end
  23.  
  24. class B
  25. include A
  26.  
  27. inc()
  28. inc()
  29. end
  30.  
  31. class C
  32. include A
  33.  
  34. inc()
  35. end
  36.  
  37. B.foo()
  38. C.foo()
  39.  
  40. # OUTPUT #
  41. 69875669805760
  42. 0
  43. 1
  44. 69875669805760
  45. 1
  46. 2
  47. 69875669805620
  48. 0
  49. 1
  50. 69875669805760
  51. 1
  52. 69875669805620
  53. 1
Add Comment
Please, Sign In to add comment