This is topic Ruby Query: in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=048943

Posted by Phanto (Member # 5897) on :
 
I've been working on a nifty program that figures out what number you're thinking of by binary division. (Is it 500? Is it 750? Is it 625?..., until it gets it.)

Then I realized a problem:

quote:

lowerbound = guessNumber.dup

This method is a string method. I could convert guessNumber back to a string, dup it, then convert back. But there has to be a better way. What's the method I need?

Thanks ^_^.

[ June 15, 2007, 02:47 PM: Message edited by: Phanto ]
 
Posted by fugu13 (Member # 2859) on :
 
dup is not a string method:

http://www.rubycentral.com/book/ref_c_object.html#Object.dup

But more importantly, why are you trying to duplicate a number?
 
Posted by Phanto (Member # 5897) on :
 
Because I want lowerbound to take the value of guessNumber and then I want to change guessNumber's value without changing that of lowerbound.
 
Posted by fugu13 (Member # 2859) on :
 
Try running the following ruby script:

code:
a = 1
b = a

a = 2

puts a
puts b


 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2