Created
May 8, 2012 14:58
-
-
Save chad/2635951 to your computer and use it in GitHub Desktop.
Revisions
-
chad revised this gist
May 8, 2012 . 1 changed file with 4 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,17 @@ module Foo def self.included(klass) klass.extend ClassMethods end module ClassMethods def foo(name) (class << self; self; end).send :attr_accessor, name end end end class Bar include Foo foo("test") end p Bar.test -
josh-m-sharpe created this gist
May 8, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ module Foo def self.included(klass) klass.extend ClassMethods end module ClassMethods def foo str = "test" class_eval do attr_accessor str class << self attr_accessor str end end end end end class Bar include Foo foo end Bar.test $ ruby ~/Desktop/test.rb /Users/test/Desktop/module.rb:12:in `foo': undefined local variable or method `str' for #<Class:Bar> (NameError) from /Users/test/Desktop/module.rb:9:in `class_eval' from /Users/test/Desktop/module.rb:9:in `foo' from /Users/test/Desktop/module.rb:22