ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Principle of le,err i mean biggest surprise!!??
by Ron Fox other posts by this author
May 9 2008 7:45AM messages near this date
Re: Principle of le,err i mean biggest surprise!!?? | Re: Principle of le,err i mean biggest surprise!!??
globalrev wrote:
>  puts "Input sentence:"
>  sentence = gets.split()
>  puts
>  
>  temp = sentence
>  phrase = sentence
>  puts ":", temp, sentence, phrase
>  
>  phrase[0] = temp[1]
>  puts "oink", phrase, temp
>  
>  when changing phrase[0] this will change temp as well and even
>  sentence! makes no sense and very surprising. 
Well actually it makes perfect sense.. given what a Ruby variable 
actually is.  See below.

how do i do what i want
>  to do?
>  
>  so basically ami messing with pointers here or what?

Yes you are.  Variables in ruby are references to their underlying 
objects.  Assignment assigns the references.  Use the dup method to 
create copies.

Ron.
Thread:
Globalrev
Rick DeNatale
Ron Fox
Marc Heiler
Matthew Moss

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved