# Updating the original reference of a variable

**URL:** <https://www.ruby-forum.com/t/updating-the-original-reference-of-a-variable/49425>\
**Category:** Ruby\
**Created:** [December 4, 2005, 5:36am UTC](https://www.ruby-forum.com/t/updating-the-original-reference-of-a-variable/49425 "2005-12-04T05:36:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 4, 2005, 5:36am UTC](https://www.ruby-forum.com/t/updating-the-original-reference-of-a-variable/49425/1 "2005-12-04T05:36:52Z")

</div>

I’m working on a library similar to what DL does and I’m having a  
problem with implementing variables that are to be passed as pointers.  
I have all the C side code working, the problem is updating the original  
variable with a modified value (for example you are calling a function  
that takes two int\* and sets their values based on some initilization).  
My setup for passing the call along to the C function is to splat the  
parameters into an array and pass the array and the function name into  
the C layer which then makes the call into the loaded library.

def dispatch(ruby\_name, \*args)  
self.class.fl\_call\_function(@function\_handles[ruby\_name], args)  
end

If in the C layer I modify the value of one of the array elements that  
value is changed when I return but I don’t have a way of propogating  
that array element’s value to the original variable that was passed in.  
Is there any way to get the object containing the variable (maybe by  
using the object\_id?) that was passed in and then use that to set a new  
value for the variable?

David K.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 5, 2005, 12:17am UTC](https://www.ruby-forum.com/t/updating-the-original-reference-of-a-variable/49425/2 "2005-12-05T00:17:09Z")

</div>

On Dec 3, 2005, at 11:36 PM, David K. wrote:

> If in the C layer I modify the value of one of the array elements  
> that value is changed when I return but I don’t have a way of  
> propogating that array element’s value to the original variable  
> that was passed in. Is there any way to get the object containing  
> the variable (maybe by using the object\_id?) that was passed in and  
> then use that to set a new value for the variable?
> 
> David K.

No. Consider changing the mapping into one that returns multiple  
values, or do something like

v = []  
def fun(x)  
x \<\< result  
end

fun(v)

# do stuff with v[0]

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 7, 2005, 1:46am UTC](https://www.ruby-forum.com/t/updating-the-original-reference-of-a-variable/49425/3 "2005-12-07T01:46:44Z")

</div>

On 12/3/05, David K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m working on a library similar to what DL does and I’m having a  
> problem with implementing variables that are to be passed as pointers.  
> I have all the C side code working, the problem is updating the original  
> variable with a modified value (for example you are calling a function  
> that takes two int\* and sets their values based on some initilization).  
> My setup for passing the call along to the C function is to splat the  
> parameters into an array and pass the array and the function name into  
> the C layer which then makes the call into the loaded library.

Ruby’s variables don’t work that way.

-austin
