Is ruby strongly or weakly typed?

IMHO Ruby is strongly but dynamically typed.


While you can get into arguments about the definition of those term I'd say:

Ruby dynamically and strongly typed while JavaScript is dynamically and weakly typed.


Wikpedia labels it as "dynamic ('duck') typed".

Regarding Pop's comment about it being "strong-typed" - I'm not sure his explanation actually fits with what goes on under the covers. The MRI doesn't really "check" to see if an operation can be performed on an object; it just sends the object the message, and if that object doesn't accept that message (either by a method declaration or by handling it in #method_missing) it barfs. If the runtime actually checked to make sure operations were possible, #method_missing wouldn't work.

Also, it should be noted that since everything in Ruby is an object (and I do mean everything), I'm not sure what he said about "not in an oo-sense" is accurate. In Ruby, you're either an object or a message.


Ruby is "strong typed".

Strong typing means an object's type (not in the OOP sense, but in a general sense) is checked before an operation requiring a certain type is executed on it.

Weak typed means that no checking is done to ensure that the operation can succeed on the object. (For example, when a function accesses a string like and array of floats, if no type checking is done then the operation is allowed)

Edit: It's been 6 years since this answer was posted and I think it warrants some extra clarifications:

Over the years the notion that "type safety is a dial not an absolute" started to be used in favor of the binary meaning (yes/no)

Ruby is "stronger" typed (with an "er") than most typical dynamic languages. The fact that ruby requires explicit statements for conversion IE: Array("foo"), "42".to_i, Float(23), brings the Ruby typing dial closer to the "Strong Typed" end of spectrum than the "weak typed".

So I would say "Ruby is a stronger typed dynamic language than most common dynamic languages"