Skip to content

Instantly share code, notes, and snippets.

@tanordheim
Created August 7, 2010 22:10
Show Gist options
  • Select an option

  • Save tanordheim/513256 to your computer and use it in GitHub Desktop.

Select an option

Save tanordheim/513256 to your computer and use it in GitHub Desktop.
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