Created
March 30, 2012 03:21
-
-
Save JoshCheek/2246180 to your computer and use it in GitHub Desktop.
What if all class methods were placed in a module?
This file contains 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
class Client | |
module ClassMethods | |
def self.extended(klass) | |
klass.url = 'http://example.com/whatever' | |
end | |
attr_accessor :url | |
end | |
extend ClassMethods | |
# instance methods go here | |
end | |
describe Client do | |
let(:client_class) { Class.new.extend Client::ClassMethods } | |
it 'is a subclass of ClientClassMethods' do | |
Client.should be_a_kind_of Client::ClassMethods | |
end | |
it 'has a default url of example.com/whatever' do | |
client_class.url.should == "http://example.com/whatever" | |
end | |
it 'can configure its url to a new value' do | |
client_class.url = "http://example.com/new_url" | |
client_class.url.should == "http://example.com/new_url" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment