https://github.com/olehdevua/contract_programming
This small gem make contract programming in ruby more convenient
https://github.com/olehdevua/contract_programming
Last synced: 18 days ago
JSON representation
This small gem make contract programming in ruby more convenient
- Host: GitHub
- URL: https://github.com/olehdevua/contract_programming
- Owner: olehdevua
- License: mit
- Created: 2014-09-05T16:10:02.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-06T22:06:14.000Z (almost 12 years ago)
- Last Synced: 2025-11-29T21:35:08.249Z (7 months ago)
- Language: Ruby
- Size: 121 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ContractProgramming
This small gem make contract programming in ruby more convenient
## Installation
In console
user:~$ git clone https://github.com/OlegTsyba/contract_programming
user:~$ cd contract_programming
user:~$ gem build contract_programming.gemspec
user:~$ gem install contract_programming-0.0.1.gem
Add this line to your application's Gemfile:
gem 'contract_programming'
And then execute:
$ bundle install
## Usage
```ruby
class Ex
extend ContractProgramming
contract def meth(num)
num.to_s
end
def pre_meth(num)
check_it 'must be a num', Fixnum === num
end
def post_meth(result)
check_it 'must be a string', String === result
end
end
Ex.new.meth 1 # successfully
Ex.new.meth '1' # raise ArgumentError, 'must be a num'
class Ex
def meth(num)
num
end
end
Ex.new.meth 1 # raise ArgumentError, 'must be a string'
```
## Contributing
1. Fork it ( https://github.com/OlegTsyba/contract_programming/fork )
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 a new Pull Request