|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
T24gQmVoYWxmIE9mIE1hcnRpbiBEdXJhaToNCiMgVGhhbmsgeW 91IGRhbmllbCwgYnV0IG15IGZ1
bmN0aW9uYWxpdHkgaXMgbm90IHJldHVybiBhcyBhIGFycmF5Lg 0KIyBJIG5lZWQgdG8gY29weSBh IHNvdXJjZSBhcnJheSB0byBhIGRlc3RpbmF0aW9uIGFycmF5Lg 0KDQppIHRoaW5rIHlvdSBvbmx5 IHdhbnQgdG8gY29weSBhIHBhcnQgKHRoZSB3aG9sZSBpcyB0cm l2aWFsKSBvZiB0aGUgYXJyYXkg YW5kIGluc2VydCBpdCB0byBhbm90aGVyIGFycmF5LCBubz8NCg 0KYQ0KIz0+IFsxLCAyLCAzLCA0 XQ0KDQpiDQojPT4gWzUsIDYsIDcsIDgsIDksIDEwXQ0KDQphWz EsMV0NCiM9PiBbMl0NCg0KYlsy Li4tMl0NCiM9PiBbNywgOCwgOV0NCg0KYVsxLDFdPWJbMi4uLT JdDQojPT4gWzcsIDgsIDldDQoN CmENCiM9PiBbMSwgNywgOCwgOSwgMywgNF0NCg0KDQpvciBtYX liZSBqdXN0IHBsYWluIGluc2Vy dCBpdCwNCg0KYVswXQ0KIz0+IDENCg0KYlswLDJdDQojPT4gWz UsIDZdDQoNCmFbMF09YlswLDJd DQojPT4gWzUsIDZdDQoNCmENCiM9PiBbWzUsIDZdLCA3LCA4LC A5LCAzLCA0XQ0KDQoNCmtpbmQg cmVnYXJkcyAtYm90cA0K |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|