Skip to content

Instantly share code, notes, and snippets.

@adamcooper
Created March 13, 2012 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcooper/2030051 to your computer and use it in GitHub Desktop.
Save adamcooper/2030051 to your computer and use it in GitHub Desktop.
class Redis
attr_accessor :server
end
class RedisNamespace
attr_accessor :redis
def initialize(namespace, options = {})
self.redis = options[:redis] || :internal
end
def test
@redis
end
end
redis = Redis.new
redis.server = :external
activity = RedisNamespace.new(:activity, :redis => redis.server)
puts "redis.server = #{redis.server}"
puts "activity.redis = #{activity.test}"
# now change the server - similar to swapping in the specs
redis.server = :changed
puts "redis.server = #{redis.server}"
puts "activity.redis = #{activity.test}"
@adamcooper
Copy link
Author

And the output

-> % ruby lib/test.rb
redis.server = external
activity.redis = external
redis.server = changed
activity.redis = external

@tjwallace
Copy link

@adamcooper shouldn't you be setting up activity like this:

RedisNamespace.new(:activity, :redis => redis)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment