This gem adds override syntax that is similar to Java's one.
override syntax ensures that a modified method has super method.
Unless the method has super method, this gem raise Overrider::NoSuperMethodError.
This gem is pseudo static code analyzer by TracePoint and Ripper.
it detect abstract violation when class(module) is defined, not runtime.
Add this line to your application's Gemfile:
gem 'overrider'And then execute:
$ bundle
Or install it yourself as:
$ gem install overrider
class A1
def foo
end
end
class A2 < A1
extend Overrider
override def foo
end
endthis is OK.
class B1
end
class B2 < B1
extend Overrider
override def foo
end
end # => raiseIf you want to disable Overrider, write Overrider.disable = true at first line.
If Overrider is disabled, TracePoint never runs, and so there is no overhead of VM instruction.
module C1
def foo
end
end
class C2
extend Overrider
override def foo
end
include C1
end # => OKclass D1
end
class D2 < D1
extend Overrider
class << self
def foo
end
end
override_singleton_method :foo
end # => raiseclass D2_1
def self.foo
end
end
class D2_2 < D2_1
extend Overrider
class << self
def foo
end
end
override_singleton_method :foo
end # => OKmodule E1
def foo
end
def bar
end
end
class E2
extend Overrider
class << self
def foo
end
def bar
end
end
override_singleton_method :foo
override_singleton_method :bar
extend E1
end # => OKclass A1
def foo
end
end
Class.new(A1) do
extend Overrider
override def foo
end
end # => OKUse TracePoint and caller_locations (to detect class-end or Class.new { }).
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/overrider.
The gem is available as open source under the terms of the MIT License.