MethodWatcher

Gem Version Build Status

Provide method_overriding callback.

Installation

Add this line to your application's Gemfile:

gem 'method_watcher'

And then execute:

$ bundle

Or install it yourself as:

$ gem install method_watcher

Usage

require 'method_watcher'

class A
  include MethodWatcher
  def foo
  end

  def bar
  end

  watch_methods :foo, :bar
  unwatch_methods :bar
end

class B < A
  def foo
  end
end

#you will get a warning:
# => method A#foo is overridden

#you can define you own behavior when method overriding.
#in class A:
def self.method_overriding method
  raise "OMG, method #{method} is overridden!!"
end

#you can also use it like ruby core methods private, protect and public
require 'method_watcher'

class A
  include MethodWatcher

  # if you pass no arguments, all methods below it will be watched
  watch_methods

  def foo
  end

  def foo2
  end

  # if you pass no arguments, it will disable watching, methods below it will not be watched
  unwatch_methods

  def bar
  end

  #in this example, methods foo, foo2 should be watched
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request