PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > How to copy arrays?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to copy arrays?

Réponse
 
LinkBack Outils de la discussion
Vieux 21/11/2007, 03h20   #1
Martin Durai
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to copy arrays?

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 me with this

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

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

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

  Réponse avec citation
Vieux 21/11/2007, 03h26   #2
Daniel N
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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 me with this
>
> System.arraycopy(elName, 0, arr, 0, elStackSize);
>
> I need a way to do samething in ruby. please any body 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

  Réponse avec citation
Vieux 21/11/2007, 03h38   #3
Martin Durai
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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-forum.com/.

  Réponse avec citation
Vieux 21/11/2007, 03h42   #4
Gregory Seidman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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(destinati on_array)
destination_array.replace @my_array
end

> Thank you in advance

--Greg


  Réponse avec citation
Vieux 21/11/2007, 03h44   #5
Daniel N
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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-forum.com/.
>
>

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

  Réponse avec citation
Vieux 21/11/2007, 04h14   #6
Peña, Botp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

T24gQmVoYWxmIE9mIE1hcnRpbiBEdXJhaToNCiMgVGhhbmsgeW 91IGRhbmllbCwgYnV0IG15IGZ1
bmN0aW9uYWxpdHkgaXMgbm90IHJldHVybiBhcyBhIGFycmF5Lg 0KIyBJIG5lZWQgdG8gY29weSBh
IHNvdXJjZSBhcnJheSB0byBhIGRlc3RpbmF0aW9uIGFycmF5Lg 0KDQppIHRoaW5rIHlvdSBvbmx5
IHdhbnQgdG8gY29weSBhIHBhcnQgKHRoZSB3aG9sZSBpcyB0cm l2aWFsKSBvZiB0aGUgYXJyYXkg
YW5kIGluc2VydCBpdCB0byBhbm90aGVyIGFycmF5LCBubz8NCg 0KYQ0KIz0+IFsxLCAyLCAzLCA0
XQ0KDQpiDQojPT4gWzUsIDYsIDcsIDgsIDksIDEwXQ0KDQphWz EsMV0NCiM9PiBbMl0NCg0KYlsy
Li4tMl0NCiM9PiBbNywgOCwgOV0NCg0KYVsxLDFdPWJbMi4uLT JdDQojPT4gWzcsIDgsIDldDQoN
CmENCiM9PiBbMSwgNywgOCwgOSwgMywgNF0NCg0KDQpvciBtYX liZSBqdXN0IHBsYWluIGluc2Vy
dCBpdCwNCg0KYVswXQ0KIz0+IDENCg0KYlswLDJdDQojPT4gWz UsIDZdDQoNCmFbMF09YlswLDJd
DQojPT4gWzUsIDZdDQoNCmENCiM9PiBbWzUsIDZdLCA3LCA4LC A5LCAzLCA0XQ0KDQoNCmtpbmQg
cmVnYXJkcyAtYm90cA0K

  Réponse avec citation
Vieux 21/11/2007, 06h58   #7
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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
  Réponse avec citation
Vieux 21/11/2007, 06h59   #8
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to copy arrays?

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h38.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13877 seconds with 16 queries