Created
November 26, 2010 16:12
-
-
Save fedesilva/716901 to your computer and use it in GitHub Desktop.
Mutable arrays suck
This file contains hidden or 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
#I would like to avoid having to explicitly clone the array. I want immutable collections. | |
ruby-1.8.7-p302 > segment = [ 192,168,20 ] | |
=> [192, 168, 20] | |
ruby-1.8.7-p302 > (180..185).map{ |i| segment.clone << i } | |
=> [[192, 168, 20, 180], [192, 168, 20, 181], [192, 168, 20, 182], [192, 168, 20, 183], [192, 168, 20, 184], [192, 168, 20, 185]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment