Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joker1007/overrider
Add `override` syntax that is similar to Java's one.
https://github.com/joker1007/overrider
Last synced: 2 days ago
JSON representation
Add `override` syntax that is similar to Java's one.
- Host: GitHub
- URL: https://github.com/joker1007/overrider
- Owner: joker1007
- License: mit
- Created: 2018-01-24T17:41:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-04T17:57:30.000Z (over 5 years ago)
- Last Synced: 2024-10-05T06:57:00.509Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 21.5 KB
- Stars: 28
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Overrider
[![Build Status](https://travis-ci.org/joker1007/overrider.svg?branch=master)](https://travis-ci.org/joker1007/overrider)
[![Gem Version](https://badge.fury.io/rb/overrider.svg)](https://badge.fury.io/rb/overrider)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.
### My similar gems
- [finalist](https://github.com/joker1007/finalist) (`final` implementation)
- [abstriker](https://github.com/joker1007/abstriker) (`abstract` implementation)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'overrider'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install overrider
## Usage
```ruby
class A1
def foo
end
endclass A2 < A1
extend Overrideroverride def foo
end
end
```this is OK.
```ruby
class B1
endclass B2 < B1
extend Overrideroverride def foo
end
end # => raise
```### for Production
If 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.### Examples
#### include module method after override method
```ruby
module C1
def foo
end
endclass C2
extend Overrideroverride def foo
endinclude C1
end # => OK
```#### singleton method
```ruby
class D1
endclass D2 < D1
extend Overriderclass << self
def foo
end
endoverride_singleton_method :foo
end # => raise
``````ruby
class D2_1
def self.foo
end
endclass D2_2 < D2_1
extend Overriderclass << self
def foo
end
endoverride_singleton_method :foo
end # => OK
```#### extend singleton method after override method
```ruby
module E1
def foo
enddef bar
end
endclass E2
extend Overriderclass << self
def foo
enddef bar
end
endoverride_singleton_method :foo
override_singleton_method :barextend E1
end # => OK
```#### `Class.new` style
```ruby
class A1
def foo
end
endClass.new(A1) do
extend Overrideroverride def foo
end
end # => OK
```## How is it implemented?
Use `TracePoint` and `caller_locations` (to detect `class-end` or `Class.new { }`).
## Development
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](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/overrider.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).