On Fri, 27 May 2005, Greg Brown wrote: >> 1) Style in general. What have I done that is 'unrubyish'? Are there >> more elegant ways of doing things? >> >> 2) If a want a 'mathematical' vector, that treats + as addition and not >> as concatenation, what can I do? I added the method 'add!' to class >> Array for this, but it would be nice to know if there is a standard >> facility for this. >> >> 3) I gave my Board class a copy method. Is there a better way to copy >> an array than concatenating the source to an empty ([]) target? I found >> no 'copy' method in the docs. > > I have some ideas about the first 2 but I'll leave it to the experts to > give you the 'good' answers. But for 3, some_copy = some_array.dup > should do the trick. i think it's often better to implement your own copy method since dup only copies the arrray - not it's contents. harp:~ > irb irb(main):001:0> a = [ hash = {:k => :v} ] => [{:k=>:v}] irb(main):002:0> a_dup = a.dup => [{:k=>:v}] irb(main):003:0> a[0]['key'] = 'value' => "value" irb(main):004:0> a_dup => [{:k=>:v, "key"=>"value"}] clone doesn't really help either irb(main):005:0> a = [ hash = {:k => :v} ] => [{:k=>:v}] irb(main):006:0> a_clone = a.clone => [{:k=>:v}] irb(main):007:0> a[0]['key'] = 'value' => "value" irb(main):008:0> a_clone => [{:k=>:v, "key"=>"value"}] my utility classes never get written w/o def copy obj Marshal::load(Marshal::dump(obj)) end although i know this is frowned upon... FYI. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================