-1
這可行,但它看起來不太合適。想知道我錯過了什麼,或者如果我能以某種方式簡化它?當塊需要變量時將塊傳遞給方法
摘掉$redis
的東西。
def redis_with_connection(&block)
$redis.with_connection { |conn| yield(conn) }
# perhaps do other stuff like begin/rescue, etc.
end
於是我可以在我的應用程序
redis_with_connection do |conn| # is this conn variable necessary here?
conn.set # do stuff with the connection
end