Created
February 12, 2013 18:04
-
-
Save patbenatar/4771872 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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