Skip to content

Instantly share code, notes, and snippets.

@mutle
Created February 8, 2011 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutle/816948 to your computer and use it in GitHub Desktop.
Save mutle/816948 to your computer and use it in GitHub Desktop.
require File.expand_path('../spec_helper', __FILE__)
describe "Class#class_eval" do
it "uses the right variable scope for class variables declared in class_eval" do
module ClassAttribute
class << self
def included(mod)
mod.class_eval <<-EOS
unless defined? @@attribute
@@attribute = nil
end
def self.attribute
@@attribute
end
def self.attribute=(obj)
@@attribute = obj
end
EOS
end
end
end
class A
include ClassAttribute
end
class B
include ClassAttribute
end
A.attribute = "PASS"
B.attribute = "FAIL"
A.attribute.should == "PASS"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment