module PrependAndAppend

Public Instance Methods

append(*methods, &block) click to toggle source
# File lib/prepend_and_append.rb, line 4
def append *methods, &block
  self.caller :append, *methods, &block
  nil
end
caller(method, *methods, &block) click to toggle source
# File lib/prepend_and_append.rb, line 14
def caller method, *methods, &block
  methods.each do |m|
    m = m.to_sym

    if defined? m
      singleton_class.send :alias_method, "old_#{m.to_s}".to_sym, m

      self.define_singleton_method m do
        block.call if block_given? && method == :prepend
        self.send "old_#{m.to_s}".to_sym
        block.call if block_given? && method == :append
      end
    end
  end
end
prepend(*methods, &block) click to toggle source
# File lib/prepend_and_append.rb, line 9
def prepend *methods, &block
  self.caller :prepend, *methods, &block
  nil
end