DEV Community

Burdette Lamar
Burdette Lamar

Posted on

3 1

Ruby Contracts: Best of Both Worlds

Among the many flame-wars in the developer community is the one about typing: static vs. dynamic.

In Ruby, we can have the best of both worlds, via gem contracts.

I was going to write about this powerful and flexible gem here, but on second thought will just link to this excellent page by the gem's author.

Top comments (2)

Collapse
 
philnash profile image
Phil Nash β€’

I'd be interested to hear your experiences with the gem. Have you found it makes it easier to write applications? Do you write fewer tests? Do you use it everywhere in a codebase or only in particular places?

Collapse
 
burdettelamar profile image
Burdette Lamar β€’

Thanks, Phil.

Using contracts makes it easier to catch bugs earlier: type error is caught immediately rather than further downstream where it's harder to debug.

For my large-scale in-house test frameworks, I've used it throughout.

For code that will become a gem, though, I don't use it, because it creates a dependency that the potential user might find unacceptable.

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay