Avoiding copies of method arguments

J

Justin To

Hello!

v = 'abc'

some-method(v)

This will send a copy of v to the method, right? If so, how does one
avoid this. How can one send the original and avoid the extra
consumption of resources from copying? Thanks!
 
S

schreiber.arthur

Hello Justin!

No, this will not send a copy of v to some_method, but v itself.

Cheers,
Arthur
 
J

J. Cooper

Just test it out:

irb >> def change(str)
irb >> str << 'z'
irb >> end
irb => nil
irb >> v
irb => "abc"
irb >> change(v)
irb => "abcz"
irb >> v
irb => "abcz"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top