[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04211] inserion in array.

From: Hugh Sasse Staff Elec Eng <hgs@...>
Date: 2000-07-25 15:42:56 UTC
List: ruby-talk #4211
The array type does not seem to have a way to insert another array inside
one array.  One can do:

irb(main):001:0> a = [ -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]
[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]
irb(main):002:0> a[10] = [3,4,5] 
[3, 4, 5]
irb(main):003:0> a
[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, [3, 4, 5]]
irb(main):004:0> a.flatten!
[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 3, 4, 5]

which is fine, but:

irb(main):012:0> a = [[1, 2, 3], 8, 9, [0, 1, 2]]
[[1, 2, 3], 8, 9, [0, 1, 2]]
irb(main):013:0> a[2]=[11,12,13]
[11, 12, 13]
irb(main):014:0> a
[[1, 2, 3], 8, [11, 12, 13], [0, 1, 2]]
irb(main):015:0> a.flatten!
[1, 2, 3, 8, 11, 12, 13, 0, 1, 2]

is not what I want, because it has flattened the whole array.  Is this a
case for an "insert" method for Array?  Or "Is There A Better Way To Do
It?"

	Hugh
	hgs@dmu.ac.uk



In This Thread

Prev Next