Skip to content

Instantly share code, notes, and snippets.

@chriswailes
Created January 18, 2011 06:04
Show Gist options
  • Save chriswailes/784035 to your computer and use it in GitHub Desktop.
Save chriswailes/784035 to your computer and use it in GitHub Desktop.
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
@chriswailes
Copy link
Author

The desired output is:
69875669805760
0
1
69875669805760
1
2
69875669805620
0
1
69875669805760
2
69875669805620
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment