# Corresponding C-method for setting and changing a local or global variable

**URL:** <https://www.ruby-forum.com/t/corresponding-c-method-for-setting-and-changing-a-local-or-global-variable/121084>\
**Category:** Ruby\
**Created:** [November 23, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/corresponding-c-method-for-setting-and-changing-a-local-or-global-variable/121084 "2007-11-23T15:15:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 23, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/corresponding-c-method-for-setting-and-changing-a-local-or-global-variable/121084/1 "2007-11-23T15:15:43Z")

</div>

its me again, still having trouble with the c-core.

im trying to find the c-method(s) which is responsible if a local or  
global variable is set.

example:

class X  
$globvar = “hey” \<- setting/instanciation of a global variable  
def hello  
hi = “hi” \<- setting/instancition of a local variable  
end  
end

I’ve found out that the responsible methods for setting a class variable  
is: rb\_cvar\_set  
, for setting an instancevariable is rb\_ivar\_set and for constants  
rb\_const\_set

I hope you can help me with finding the right methods for local and  
global vars

thanks so much!!

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 24, 2007, 2:15am UTC](https://www.ruby-forum.com/t/corresponding-c-method-for-setting-and-changing-a-local-or-global-variable/121084/2 "2007-11-24T02:15:31Z")

</div>

removed\_email\_address@domain.invalid wrote:

> end  
> end
> 
> I’ve found out that the responsible methods for setting a class variable is: rb\_cvar\_set  
> , for setting an instancevariable is rb\_ivar\_set and for constants rb\_const\_set
> 
> I hope you can help me with finding the right methods for local and global vars
> 
> thanks so much!!

Define a global variable with rb\_define\_variable. Set and get the  
variable’s value with rb\_gv\_set and rb\_gv\_get.

There is no function that works with local variables.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 25, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/corresponding-c-method-for-setting-and-changing-a-local-or-global-variable/121084/3 "2007-11-25T22:52:50Z")

</div>

_push_  
----- Original Message -----  
From: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, November 23, 2007 3:14 PM  
Subject: corresponding C-method for setting and changing a local or  
global  
variable

its me again, still having trouble with the c-core.

im trying to find the c-method(s) which is responsible if a local or  
global  
variable is set.

example:

class X  
$globvar = “hey” ← setting/instanciation of a global variable  
def hello  
hi = “hi” ← setting/instancition of a local variable  
end  
end

I’ve found out that the responsible methods for setting a class variable  
is:  
rb\_cvar\_set  
, for setting an instancevariable is rb\_ivar\_set and for constants  
rb\_const\_set

I hope you can help me with finding the right methods for local and  
global  
vars

thanks so much!!
