learned ruby a few months ago - is there a pointer equivalent in ruby
for setting the variable referenced by the return value of a function,
rather than just getting it?
Well generally for such situations you create setters, the example you gave
includes only a getter.
def method=(val) @value = val
end
that will then allow you to do method = 3 & that will in turn set @value to
3.
Although I don't see what exactly you wanted to know or what you're example
had to do with pointers...
···
--
Thanks & Regards,
Dhruva Sagar.
On Sun, Oct 17, 2010 at 21:29, Shea Barton <shea@sysach.com> wrote:
learned ruby a few months ago - is there a pointer equivalent in ruby
for setting the variable referenced by the return value of a function,
rather than just getting it?
method = 3 will always assign to a local variable. If you really want to produce other side effects you need to do
self.method = 3
The topic seems to come up more frequently in recent time. I don't know whether Ruby community experiences increased migration from C++ developers or what the reason for this is. I believe the fact that people search for something call by reference in said language indicates that they do not have adjusted to the Ruby mindset yet. Shea, if you provide more context we might be able to help you understand how the problem you are trying to solve is usually solved in Ruby - without call by reference.