变量一定要有类型吗(二) 变量一定要有类型吗?不一定。 在《The Ruby Way 2nd》一书中,1.2.3节 Constants, Variables, and Types “In Ruby, variables do not have types, but the objects they refer to still have types. ” 在Ruby中,变量没有类型,但变量引用的对象有类型。 1.5.2节 Perspectives in Programming “In Ruby, variables don't have classes; only values hav ...
先讨论一下Ruby是不是强类型。 1).在《Beyond Java》September 2005 一书 6.1.2节Typing 中,Bruce Tate举例 irb(main):015:0> "fish"+4 TypeError: cannot convert Fixnum into String from (irb):15:in‘+’ from (irb):15 从而得出结论: 引用 That means Ruby is strongly typed. 我们知道,Ruby是动态语言,在运行中边解释、边检测、边执 ...
凌川__
搜索本博客
最近加入圈子
存档
最新评论
评论排行榜