From: Josh Cheek Date: 2010-11-12T21:54:03+09:00 Subject: Re: Ruby vs PHP for the web --001485f80ea4a325860494da95ea Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2010/11/12 Jes=FAs Gabriel y Gal=E1n > On Thu, Nov 11, 2010 at 11:50 PM, Mike Stephens > wrote: > > Charles Calvert wrote in post #960599: > >> Ruby uses > >> strong, though dynamic, typing. > > > > Can you explain what you mean? That seems a contradiction in terms. > > http://en.wikipedia.org/wiki/Strong_typing > > It means that the language imposes restrictions about how different > types are mixed, and avoids implicit conversions of types, among other > things. Compare: > > Javascript (weak typing): > > 2 + '2' =3D> '22' > > Ruby (strong typing): > > 2 + '2' =3D> TypeError: String can't be coerced into Fixnum > Is Ruby strongly typed? 2 + 2.0 # =3D> 4.0 Here it has implicitly converted the integer 2 to a float, in order to be able to add them. You can even make your specific example pass, exactly as written, by defining String#coerce: class String def coerce(num) return num.to_s , self end end 2 + '2' # =3D> "22" --001485f80ea4a325860494da95ea--