# Programming By Contract with Ruby

**URL:** <https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323>\
**Category:** Ruby\
**Created:** [September 11, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323 "2008-09-11T19:01:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [September 11, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323/1 "2008-09-11T19:01:09Z")

</div>

Hi Folks,

Does anyone know of a Programming By Contract framework for ruby? It  
seems like fertile ground, given the dynamic nature of the language. I’m  
imagining some kind of DSL that allows a developer to annotate a  
class/module with invariants, and also to annotate methods with pre- and  
post-conditions.

Cheers,  
Pete

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [September 11, 2008, 9:21pm UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323/2 "2008-09-11T21:21:06Z")

</div>

I have an example on the Aquarium site of doing basic “design  
(programming)  
by contract”. Look near the bottom of this page for “Design by  
Contract”:  
[http://aquarium.rubyforge.org/examples.html](http://aquarium.rubyforge.org/examples.html)

dean

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [September 11, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323/3 "2008-09-11T23:13:10Z")

</div>

Thanks Dan.

Looks like dbc is actually a Design By Contract system for C, using ruby  
and Racc to parse an external DSL:  
[Radar – O’Reilly](http://www.onlamp.com/pub/a/onlamp/2004/10/28/design_by_contract_in_c.html).

I’ll take a look at rubydbc. Anyone else have any input?

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [September 11, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323/4 "2008-09-11T21:50:23Z")

</div>

On Sep 11, 10:53 am, Pete H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Folks,
> 
> Does anyone know of a Programming By Contract framework for ruby? It  
> seems like fertile ground, given the dynamic nature of the language. I’m  
> imagining some kind of DSL that allows a developer to annotate a  
> class/module with invariants, and also to annotate methods with pre- and  
> post-conditions.
> 
> Cheers,  
> Pete

[http://rubyforge.org/projects/rubydbc/](http://rubyforge.org/projects/rubydbc/)  
[http://rubyforge.org/projects/dbc/](http://rubyforge.org/projects/dbc/)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [September 12, 2008, 1:20am UTC](https://www.ruby-forum.com/t/programming-by-contract-with-ruby/148323/5 "2008-09-12T01:20:49Z")

</div>

Daniel B. wrote:

> On Sep 11, 10:53 am, Pete H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Does anyone know of a Programming By Contract framework for ruby? It  
> > seems like fertile ground, given the dynamic nature of the language. I’m  
> > imagining some kind of DSL that allows a developer to annotate a  
> > class/module with invariants, and also to annotate methods with pre- and  
> > post-conditions.  
> > [http://rubyforge.org/projects/rubydbc/](http://rubyforge.org/projects/rubydbc/)  
> > [http://rubyforge.org/projects/dbc/](http://rubyforge.org/projects/dbc/)

There’s also [https://RubyForge.Org/projects/handshake/](https://RubyForge.Org/projects/handshake/). I have no  
experience with any of those three, but I like the clever name (-:

jwm
