Created
November 29, 2011 16:49
-
-
Save duritong/1405488 to your computer and use it in GitHub Desktop.
ruby class var foo
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
require 'active_support' | |
module ModuleA | |
def self.included(c) | |
c.class_attribute :foo | |
c.extend ClassMethods | |
end | |
module ClassMethods | |
def set_foo(value) | |
self.foo = value | |
end | |
end | |
end | |
class ClassA | |
include ModuleA | |
set_foo 'foo' | |
end | |
class ClassAA | |
include ModuleA | |
set_foo 'bar' | |
end | |
class ClassB < ClassA | |
end | |
puts "A: #{ClassA.foo} (should be foo)" | |
puts "AA: #{ClassAA.foo} (should be bar)" | |
puts "B: #{ClassB.foo} (shoule be foo)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment