Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ruby object references vs collection references
  2. numbers = ["one", "two", "three"]
  3.        
  4. numbers[2] = "four"
  5.        
  6. numbers[2].replace("four")
  7.        
  8. numbers.replace [1,2,3]
  9. TypeError: can't modify frozen array
  10.        
  11. ree-1.8.7> numbers[2].object_id
  12.  => 2149301040
  13. ree-1.8.7> numbers[2].replace "four"
  14.  => "four"
  15. ree-1.8.7> numbers[2].object_id
  16.  => 2149301040