Skip to content

Instantly share code, notes, and snippets.

@adamcooper

adamcooper/test.rb

Created Mar 13, 2012
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@adamcooper adamcooper commented Mar 13, 2012

And the output

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

This comment has been minimized.

Copy link

@tjwallace tjwallace commented Mar 13, 2012

@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
You can’t perform that action at this time.