Skip to content

Instantly share code, notes, and snippets.

@amyroi
Created March 16, 2016 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyroi/5eeba07b6d0d16e01fe1 to your computer and use it in GitHub Desktop.
Save amyroi/5eeba07b6d0d16e01fe1 to your computer and use it in GitHub Desktop.
インスタンスメソッドへHookの設定
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