Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Doubt in -- Ruby --> Array --> array.display -- method

Reply
Thread Tools

Doubt in -- Ruby --> Array --> array.display -- method

 
 
jazzez ravi
Guest
Posts: n/a
 
      02-28-2009
Hi All,

I created few (array's method related) questions in ruby. But I am not
clear about one question. Here is the question ..


Question 7
(from
http://raveendran.wordpress.com/2009...ted-excercise/)

@a=[34,45,56,2,13,54]

@b= @a[2].display.to_i + @a[3].display.to_i

puts @b gives,

a) Error b) 58 c) 5620 d) 562

This is the question. In my view,

MY Solution 1:

@a[2].display.to_i => 56.display gives 56.to_i => 56
@a[3].display.to_i => 2.diaply gives 2.to_i => 2

@b= 56 + 2

@b must come as 58

MY Solution 2:

56.display -> displays 56 -> Here .to_i will not work

So my answers is,

@b= 562


But the result came as 5620 . how it works ?

Thanks,
P.Raveendran
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Siep Korteling
Guest
Posts: n/a
 
      02-28-2009
jazzez ravi wrote:
> Hi All,
>
> I created few (array's method related) questions in ruby. But I am not
> clear about one question. Here is the question ..
>
>
> Question 7
> (from
> http://raveendran.wordpress.com/2009...ted-excercise/)
>
> @a=[34,45,56,2,13,54]
>
> @b= @a[2].display.to_i + @a[3].display.to_i
>
> puts @b gives,
>
> a) Error b) 58 c) 5620 d) 562
>
> This is the question. In my view,

(...)
>
> MY Solution 2:
>
> 56.display -> displays 56 -> Here .to_i will not work
>
> So my answers is,
>
> @b= 562
>
>
> But the result came as 5620 . how it works ?
>
> Thanks,
> P.Raveendran


56.display -> prints 56 and returns nil.
nil.to_i returns 0
So @b equals zero

hth,

Siep
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dotnet doubt can any body clarify my doubt challa462@gmail.com ASP .Net 0 08-22-2012 06:02 AM
& - FixNum - method doubt jazzez ravi Ruby 10 03-30-2009 10:04 AM
doubt about doubt Bob Nelson C Programming 11 07-30-2006 08:17 PM
doubt abt finalizer method chandu Java 22 01-04-2006 06:40 PM
doubt on postback method Saravana ASP .Net 1 10-31-2004 07:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57