FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Ruby Query:

   
Author Topic: Ruby Query:
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
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 ]

Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
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?

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
Because I want lowerbound to take the value of guessNumber and then I want to change guessNumber's value without changing that of lowerbound.
Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Try running the following ruby script:

code:
a = 1
b = a

a = 2

puts a
puts b


Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

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