Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module A
- def A.included(klass)
- klass.instance_exec do
- @@foo = 0
- def inc()
- puts self.object_id
- puts @@foo
- @@foo += 1
- puts @@foo
- end
- def foo()
- puts self.object_id
- puts @@foo
- end
- end
- end
- end
- class B
- include A
- inc()
- inc()
- end
- class C
- include A
- inc()
- end
- B.foo()
- C.foo()
- # OUTPUT #
- 69875669805760
- 0
- 1
- 69875669805760
- 1
- 2
- 69875669805620
- 0
- 1
- 69875669805760
- 1
- 69875669805620
- 1
Add Comment
Please, Sign In to add comment