Skip to content

Instantly share code, notes, and snippets.

@abriening
Created August 27, 2010 12:55
Show Gist options
  • Save abriening/553298 to your computer and use it in GitHub Desktop.
Save abriening/553298 to your computer and use it in GitHub Desktop.
class A
def a_method
"a_method"
end
@@a_class_attribute = "A::a_class_attribute"
def a_class_attribute
@@a_class_attribute
end
def self.a_class_attribute=(value)
@@a_class_attribute = value
end
end
a = A.new
a.a_method # => "a_method"
a.a_class_attribute # => "A::a_class_attribute"
module B
def a_method
"b_method"
end
def self.extended(object)
super
# this modifies the class_attribute of the A class
object.class.a_class_attribute = "B::a_class_attribute"
end
end
b = A.new
b.extend B
b.a_method # => "b_method"
b.a_class_attribute # => "B::a_class_attribute"
a.a_method # => "a_method"
a.a_class_attribute # => "B::a_class_attribute" # probably not intended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment