[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to copy arrays?

dare ruby

11/21/2007 3:20:00 AM

I came accross another problem, how to copy arrays? Actually i need to
copy array just like in java. i will include the source code of java.
The same functionality i need in ruby. please any body help me with this

System.arraycopy(elName, 0, arr, 0, elStackSize);

I need a way to do samething in ruby. please any body help me with code
for arraycopy.

thanks in advance
--
Posted via http://www.ruby-....

7 Answers

Daniel N

11/21/2007 3:27:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

On Nov 21, 2007 2:20 PM, Martin Durai <martin@angleritech.com> wrote:

> I came accross another problem, how to copy arrays? Actually i need to
> copy array just like in java. i will include the source code of java.
> The same functionality i need in ruby. please any body help me with this
>
> System.arraycopy(elName, 0, arr, 0, elStackSize);
>
> I need a way to do samething in ruby. please any body help me with code
> for arraycopy.
>
> thanks in advance
>

The java doesn't mean anything to me :) That make me very happy.

@array.dup is the way to copy any object in ruby

dare ruby

11/21/2007 3:39:00 AM

0

Thank you daniel, but my functionality is not return as a array.
I need to copy a source array to a destination array.

Thank you in advance
--
Posted via http://www.ruby-....

Gregory Seidman

11/21/2007 3:42:00 AM

0

On Wed, Nov 21, 2007 at 12:38:36PM +0900, Martin Durai wrote:
> Thank you daniel, but my functionality is not return as a array.
> I need to copy a source array to a destination array.

def java_inspired_method_sans_idiomatic_ruby(destination_array)
destination_array.replace @my_array
end

> Thank you in advance
--Greg


Daniel N

11/21/2007 3:45:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

On Nov 21, 2007 2:38 PM, Martin Durai <martin@angleritech.com> wrote:

> Thank you daniel, but my functionality is not return as a array.
> I need to copy a source array to a destination array.
>
> Thank you in advance
> --
> Posted via http://www.ruby-....
>
>
I don't understand what your asking then. This is a fairly standard way to
copy an object.
@array = [1,2,3,4,5]

@new_array = @array.dup

Peña, Botp

11/21/2007 4:14:00 AM

0

T24gQmVoYWxmIE9mIE1hcnRpbiBEdXJhaToNCiMgVGhhbmsgeW91IGRhbmllbCwgYnV0IG15IGZ1
bmN0aW9uYWxpdHkgaXMgbm90IHJldHVybiBhcyBhIGFycmF5Lg0KIyBJIG5lZWQgdG8gY29weSBh
IHNvdXJjZSBhcnJheSB0byBhIGRlc3RpbmF0aW9uIGFycmF5Lg0KDQppIHRoaW5rIHlvdSBvbmx5
IHdhbnQgdG8gY29weSBhIHBhcnQgKHRoZSB3aG9sZSBpcyB0cml2aWFsKSBvZiB0aGUgYXJyYXkg
YW5kIGluc2VydCBpdCB0byBhbm90aGVyIGFycmF5LCBubz8NCg0KYQ0KIz0+IFsxLCAyLCAzLCA0
XQ0KDQpiDQojPT4gWzUsIDYsIDcsIDgsIDksIDEwXQ0KDQphWzEsMV0NCiM9PiBbMl0NCg0KYlsy
Li4tMl0NCiM9PiBbNywgOCwgOV0NCg0KYVsxLDFdPWJbMi4uLTJdDQojPT4gWzcsIDgsIDldDQoN
CmENCiM9PiBbMSwgNywgOCwgOSwgMywgNF0NCg0KDQpvciBtYXliZSBqdXN0IHBsYWluIGluc2Vy
dCBpdCwNCg0KYVswXQ0KIz0+IDENCg0KYlswLDJdDQojPT4gWzUsIDZdDQoNCmFbMF09YlswLDJd
DQojPT4gWzUsIDZdDQoNCmENCiM9PiBbWzUsIDZdLCA3LCA4LCA5LCAzLCA0XQ0KDQoNCmtpbmQg
cmVnYXJkcyAtYm90cA0K

Robert Klemme

11/21/2007 6:58:00 AM

0

On 21.11.2007 04:38, Martin Durai wrote:
> Thank you daniel, but my functionality is not return as a array.
> I need to copy a source array to a destination array.

Maybe before we go off guessing you can show a bit more of your code.
While there are methods to copy and insert into another array, maybe
there is a more efficient solution.

Cheers

robert

Robert Klemme

11/21/2007 7:00:00 AM

0

On 21.11.2007 07:58, Robert Klemme wrote:
> On 21.11.2007 04:38, Martin Durai wrote:
>> Thank you daniel, but my functionality is not return as a array.
>> I need to copy a source array to a destination array.
>
> Maybe before we go off guessing you can show a bit more of your code.
> While there are methods to copy and insert into another array, maybe
> there is a more efficient solution.

I meant to include this

irb(main):007:0> a=(1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):008:0> a[2,4]=%w{a b c}
=> ["a", "b", "c"]
irb(main):009:0> a
=> [1, 2, "a", "b", "c", 7, 8, 9, 10]
irb(main):010:0> a.concat %w{foo bar}
=> [1, 2, "a", "b", "c", 7, 8, 9, 10, "foo", "bar"]
irb(main):011:0> a
=> [1, 2, "a", "b", "c", 7, 8, 9, 10, "foo", "bar"]
irb(main):012:0>

robert