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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -