Skip to content

Instantly share code, notes, and snippets.

@codeslinger
Created March 16, 2010 20:57
Show Gist options
  • Save codeslinger/334501 to your computer and use it in GitHub Desktop.
Save codeslinger/334501 to your computer and use it in GitHub Desktop.
problem with module attribute keeping value over multiple Rails requests
#
# -=[ 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