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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -