Forum: Ruby Interface coding by contract design and dependency injection

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81fc062528fff2d38b393dab081873fe?d=identicon&s=25 PerfectDayToChaseTornados (Guest)
on 2007-01-29 19:46
(Received via mailing list)
Hi All,

I am a Java developer of many years & just starting to get into Ruby (&
really enjoying it!). However I am used to 'coding by contract' using
interfaces. This is especially great when using dependency injection
(usually via Spring). It makes testing very easy, as 'mocks' can be
written
simply & then plugged in. I know that there isn't an equvalent for an
interface in Ruby, but is there a pattern which would typically be used?
I
was wondering whether to create Modules in place of my interfaces &
provide
them with methods which throw Exceptions, thus forcing them to be
overrriden
in the classes that include them? Also how does one manage dependency
injection in Ruby? Is there a good framework/library/pattern typically
used
for this, or are there good 'Ruby reasons' not to use DI?

Many thanks
7b4707f974af261f71943e1f2046c9ee?d=identicon&s=25 SonOfLilit (Guest)
on 2007-01-29 20:10
(Received via mailing list)
Thee third google result for "dependency injection" is ruby-specific.
Ac0085dae0703db56ad7f8cb9e1798ba?d=identicon&s=25 unknown (Guest)
on 2007-01-29 21:28
(Received via mailing list)
SonOfLilit wrote:
> Thee third google result for "dependency injection" is ruby-specific.

For me, it's a German Wikipedia article on DI.

http://de.wikipedia.org/wiki/Dependency_Injection

- Phill
4e8d94859927eab3b50486d21249c068?d=identicon&s=25 Paulo Köch (Guest)
on 2007-01-29 23:13
(Received via mailing list)
Did you mean http://onestepback.org/index.cgi/Tech/Ruby/
DependencyInjectionInRuby.rdoc ?

Paulo Jorge Duarte
Köchpaulo.koch@gmail.com
85ae830f08b5ff5e39a1cbae9e3d0205?d=identicon&s=25 Olivier (Guest)
on 2007-01-30 00:24
(Received via mailing list)
Hi,

I'm really new to dependency injection in general, but I hope I can
help,
though. I am aware of two libraries for what you want to do. Copland,
first,
is an Inversion of Control (IoC) container, based on the Hivemind IoC
container for java.
As you said, there is no interface in Ruby, so Interface based injection
is
not supported. However, Type 2 IoC (Setter Injection) and type 3 IoC
(Constructor Injection) are supported.
The second is Needle, which is a Dependency Injection container. I don't
know
much about it, except it supports a Service Locator mechanism.

By the way, the documentations are great for both ! Read them both and
make
your choice !

http://needle.rubyforge.org/
http://copland.rubyforge.org/

--
Olivier Renaud

Le lundi 29 janvier 2007 19:45, PerfectDayToChaseTornados a écrit :
81fc062528fff2d38b393dab081873fe?d=identicon&s=25 PerfectDayToChaseTornados (Guest)
on 2007-01-30 20:55
(Received via mailing list)
Thanks Guys,

I'll check out Copland & Needle, anyone have any experience with either
of
these with Rails?
Ac0085dae0703db56ad7f8cb9e1798ba?d=identicon&s=25 unknown (Guest)
on 2007-01-30 21:38
(Received via mailing list)
Paulo Köch wrote:
> Did you mean
> http://onestepback.org/index.cgi/Tech/Ruby/Depende... ?
>
> Paulo Jorge Duarte Köch
> paulo.koch@gmail.com

That didn't show up for me. Google results are depending on which data
center you catch, so just saying "google, and result #X will be
relevant" is a questionable technique to answer a question.

--
Over by the window lie the raiment and the weapons
That we need to take into this world today
Armoured by opinion, with statistic and schoolboy's charm
We take our place amongst the rank and file

Skyclad - A Survival Campaign
This topic is locked and can not be replied to.