April 2010
3 posts
‘Now will this be everything, or…’
‘Well, I might need...
– JRM at Abstract Heresies
Be mindful of array copying
Trying
irb> d = [1,2,3,4]
=> [1,2,3,4]
irb> d[0..-2].each_with_index {|k,i| d[i+1] = "x"; puts k }
1
2
3
=> [1,2,3]
irb> d
[1, "x", "x", "x"]
Reasonable, d[0..-2] would make a copy of d
irb> d.each_with_index {|k,i| d[i+1] = "x" if i < 3; puts k }
1
x
x
x
=> [1,2,3]
irb> d
[1, "x", "x", "x"]
"Best Writing Advice for Engineers I've Ever Seen.... →
How to make engineers write concisely with sentences? [combine] journalism with the technical report format.