Is ruby strongly or weakly typed?

后端 未结 7 1321
Happy的楠姐
Happy的楠姐 2020-12-14 01:10

Is ruby strongly or weakly typed ?

Presumably the same is true for Javascript.

7条回答
  •  醉梦人生
    2020-12-14 01:49

    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.

提交回复
热议问题