Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created March 30, 2012 03:21
Show Gist options
  • Save JoshCheek/2246180 to your computer and use it in GitHub Desktop.
Save JoshCheek/2246180 to your computer and use it in GitHub Desktop.
What if all class methods were placed in a module?
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