module Hatenablog::AfterHook
Public Instance Methods
after_hook(hook, *methods)
click to toggle source
Register a hooking method for given methods. The hook method is executed after calling given methods. @param [Symbol] hooking method name @param [Array] hooked methods name array
# File lib/hatenablog/entry.rb, line 13 def after_hook(hook, *methods) methods.each do |method| origin_method = "#{method}_origin".to_sym if instance_methods.include? origin_method raise NameError, "#{origin_method} isn't a unique name" end alias_method origin_method, method define_method(method) do |*args, &block| # @type var block: ^(*untyped) -> untyped result = send(origin_method, *args, &block) send(hook) result end end end