Created
August 7, 2010 22:10
-
-
Save tanordheim/513256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module TestModule | |
| def self.included(base) | |
| base.extend ClassMethods | |
| end | |
| module ClassMethods | |
| def foo | |
| attr_accessor :test | |
| end | |
| end | |
| end | |
| class TestClass | |
| include TestModule | |
| foo | |
| end | |
| t = TestClass.new | |
| t.test = "test" | |
| puts "Test is #{t.test}" # Yields "Test is test" | |
| t2 = Class.new do | |
| include TestModule | |
| foo | |
| end | |
| t2.test = "foo" | |
| puts "Test is #{t2.test}" # Yields "test.rb:27: undefined method `test=' for #<Class:0x7fa3522cc4d0> (NoMethodError)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment