I’m new to Ruby - actually new to dynamically typed languages in
general. I’m from more of a C++ and C# (strongly-typed and
One thing I’m trying to wrap my brain around is the lack of explicit
interface definitions. In C# we use interfaces so that client code can
program against an abstract interface, and then you can give that client
any concrete implementation of that interface as needed. Interfaces
provide a level of abstraction/indirection that increase reusability and
Now, in Ruby, I like the “walk like a duck” approach. Actually, it’s
similar to C++ templates which are very powerful.
But there are two things that I worry about as I forge ahead in my new
In C# I can write code that can query an object for the interfaces it
implements to find out what I can do with it. (Rarely used but
sometimes a lifesaver). In Ruby I guess I have to use .methods to find
out what methods it implements?
In C# I can insure that a function is given an object that implements
a certain interface. If I don’t, it’s a compile-time error and I know
it before I ship it. In Ruby, I won’t know if I accidentally pass in
the wrong object until runtime. I might not catch it before I ship the
Can anyone provide some enlightenment?