Created
March 16, 2010 20:57
-
-
Save codeslinger/334501 to your computer and use it in GitHub Desktop.
problem with module attribute keeping value over multiple Rails requests
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
# | |
# -=[ Problem ]=- | |
# | |
# On the first Rails request, after calling Foo.configure in | |
# config/environments/development.rb, @@provider is the correct | |
# object and so Foo.doit() succeeds. On the second request, though, | |
# it raises the ArgumentError b/c @@provider is now nil. What am I | |
# doing wrong? | |
# | |
# This file lives in lib/foo.rb in a Rails 2.3.5 project | |
# (RubyEE 1.8.7). | |
# | |
module Foo | |
mattr_reader :provider | |
def self.configure options={} | |
@@provider = Foo::Bar.new(options) | |
end | |
def self.doit arg | |
raise ArgumentError unless @@provider | |
@@provider.doit(arg) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment