Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created November 26, 2010 16:12
Show Gist options
  • Save fedesilva/716901 to your computer and use it in GitHub Desktop.
Save fedesilva/716901 to your computer and use it in GitHub Desktop.
Mutable arrays suck
#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