Created
October 27, 2011 09:31
-
-
Save cemeng/1319165 to your computer and use it in GitHub Desktop.
Things that I learned about Ruby Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby-1.9.2-p290 :032 > a = [ [1,2], [3,4] ] | |
=> [[1, 2], [3, 4]] | |
ruby-1.9.2-p290 :033 > b = a.dup | |
=> [[1, 2], [3, 4]] | |
ruby-1.9.2-p290 :034 > c = a.clone | |
=> [[1, 2], [3, 4]] | |
ruby-1.9.2-p290 :035 > d = Array.new(a) | |
=> [[1, 2], [3, 4]] | |
ruby-1.9.2-p290 :036 > a[0][0] = 100 | |
=> 100 | |
ruby-1.9.2-p290 :037 > a[0][1] = 100 | |
=> 100 | |
ruby-1.9.2-p290 :038 > p a | |
[[100, 100], [3, 4]] | |
=> [[100, 100], [3, 4]] | |
ruby-1.9.2-p290 :039 > p b | |
[[100, 100], [3, 4]] | |
=> [[100, 100], [3, 4]] | |
ruby-1.9.2-p290 :040 > p c | |
[[100, 100], [3, 4]] | |
=> [[100, 100], [3, 4]] | |
ruby-1.9.2-p290 :041 > p d | |
[[100, 100], [3, 4]] | |
=> [[100, 100], [3, 4]] | |
ruby-1.9.2-p290 :042 > a[0].object_id | |
=> 2152634120 | |
ruby-1.9.2-p290 :043 > b[0].object_id | |
=> 2152634120 | |
ruby-1.9.2-p290 :044 > c[0].object_id | |
=> 2152634120 | |
ruby-1.9.2-p290 :045 > d[0].object_id | |
=> 2152634120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment