From f00853bee81877feae50f381e372ae9b46811d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98rjan=20Blom?= Date: Sun, 10 Feb 2013 00:02:29 +0100 Subject: [PATCH] Use define_method instead of eval-ing a string It avoids the need for escaping the interpolations. --- lib/discourse_redis.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 4c8df3fe3f7..c6f824c0476 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -25,12 +25,10 @@ class DiscourseRedis pttl rename renamenx rpop rpoplpush rpush rpushx sadd scard sdiff set setbit setex setnx setrange sinter sismember smembers sort spop srandmember srem strlen sunion ttl type watch zadd zcard zcount zincrby zrange zrangebyscore zrank zrem zremrangebyrank zremrangebyscore zrevrange zrevrangebyscore zrevrank zrangebyscore).each do |m| - class_eval %{ - def #{m}(*args) - args[0] = "\#\{DiscourseRedis.namespace\}:\#\{args[0]\}" - @redis.#{m}(*args) - end - } + define_method m do |*args| + args[0] = "#{DiscourseRedis.namespace}:#{args[0]}" + @redis.send(__method__, *args) + end end def self.namespace