ruby on rails - Call methods from blocks -


i using connection_pool manage connections redis, @ moment need use $redis.with {|conn| conn.set("key", 1)} set key.

how can like

redis.set("key", 1) 

and have same effect above line.

or @ least

redis(set("key", 1)) 

although see no reason in doing you’ve asked, here go:

class << redis   def my_set key, value     $redis.with { |conn| conn.set key, value }   end end 

and then:

redis.my_set 'key', 1 

for methods of interest:

class << redis   %i(set foo bar).each |m|     class_eval <<-ceeof       def my_#{m} *args         $redis.with { |conn| conn.#{m} *args }       end     ceeof   end end 

the list of methods might automatically yielded conn.instance_methods(false).


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -