From: Tony Arcieri Date: 2013-03-10T05:28:44+09:00 Subject: Re: type casting and connversion in ruby --bcaec51ddd492a6eca04d783c9ab Content-Type: text/plain; charset=ISO-8859-1 On Sat, Mar 9, 2013 at 11:56 AM, Kumar R. wrote: > With the below code what it did - casting or conversion? > > "12".to_i #=> 12 > "abc12".to_i #=> 0 > I wouldn't use either word for this. I'd call it "coersion". Ruby does support a form of "casting" using the "Integer" method: irb(main):001:0> Integer("12") => 12 irb(main):002:0> Integer("abc12") ArgumentError: invalid value for Integer(): "abc12" -- Tony Arcieri --bcaec51ddd492a6eca04d783c9ab Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Sat, Mar 9, 2013 at 11:56 AM, Kumar R. <lists@ruby-forum.com> wrote:
With= the below code what it did - casting or conversion?

"12".to_i #=3D> 12
"abc12".to_i #=3D> 0

I wouldn't use either word for this. I'd call it "coersion&qu= ot;.

Ruby does support a form of "= ;casting" using the "Integer" method:

irb(main):001:0> Integer("12&q= uot;)
=3D> 12
irb(main):002:0> Integer("abc1= 2")
ArgumentError: invalid value for Integer(): "abc12&= quot;

--
Tony Arcieri
--bcaec51ddd492a6eca04d783c9ab--