Skip to content

Instantly share code, notes, and snippets.

@patbenatar
Created February 12, 2013 18:04
Show Gist options
  • Select an option

  • Save patbenatar/4771872 to your computer and use it in GitHub Desktop.

Select an option

Save patbenatar/4771872 to your computer and use it in GitHub Desktop.
class Foo
attr_reader :adapter
def initialize
@adapter = if Rails.env.production?
Foo::RealAdapter.new
else
Foo::StubAdapter.new
end
end
# Class-level API
# Instantiates and calls instance-level methods (below)
class << self
def add_bar
new.add
end
def delete_bar
new.delete
end
end
# Instance-level API
# Just delegates through to the adapter
delegate :add, :delete, to: :adapter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment