Created
March 16, 2016 06:00
-
-
Save amyroi/5eeba07b6d0d16e01fe1 to your computer and use it in GitHub Desktop.
インスタンスメソッドへHookの設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hook | |
def increment | |
super | |
expire | |
end | |
end | |
class Ranking | |
prepend Hook | |
attr_accessor :key | |
def initialize(key) | |
@key = key | |
end | |
def increment | |
REDIS.zincrby(key, 1) | |
end | |
def expire(day = 31) | |
REDIS.expire(key, day.days.to_i) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment