# Extending an object

**URL:** <https://www.ruby-forum.com/t/extending-an-object/74024>\
**Category:** Ruby\
**Created:** [February 27, 2006, 8:18am UTC](https://www.ruby-forum.com/t/extending-an-object/74024 "2006-02-27T08:18:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [February 27, 2006, 8:18am UTC](https://www.ruby-forum.com/t/extending-an-object/74024/1 "2006-02-27T08:18:40Z")

</div>

I’m writing an extension for Ruby, and want to extend an object with  
methods from a module. I’m doing it like this:

rb\_extend\_object(self, rb\_mAModuleExtension);

But the methods added to self become private. I want them public. How  
should this be done?

Thanks in advance.

–  
Gerardo S.  
“Between individuals, as between nations, respect for the rights of  
others is peace” - Don Benito Juárez

> **[Santana's Tech Notes](http://santanatechnotes.blogspot.com/)**
>
> Small notes about technical related stuff I do, mainly OpenBSD and Ruby

---

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [February 27, 2006, 10:47am UTC](https://www.ruby-forum.com/t/extending-an-object/74024/2 "2006-02-27T10:47:34Z")

</div>

On Mon, 2006-02-27 at 16:16 +0900, Gerardo S. GÃ³mez Garrido wrote:

> I’m writing an extension for Ruby, and want to extend an object with  
> methods from a module. I’m doing it like this:
> 
> rb\_extend\_object(self, rb\_mAModuleExtension);
> 
> But the methods added to self become private. I want them public. How  
> should this be done?

I think rb\_extend\_object retains the original access of module instance  
methods, so you should need to just define them public in the module  
you’re extending.

---

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [February 28, 2006, 3:51am UTC](https://www.ruby-forum.com/t/extending-an-object/74024/3 "2006-02-28T03:51:09Z")

</div>

Thanks Ross, it’s solved. For the record, I was using  
rb\_define\_module\_function insted of rb\_define\_method for defining a  
method in the module.

2006/2/27, Ross B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> methods, so you should need to just define them public in the module  
> you’re extending.
> 
> –  
> Ross B. - removed\_email\_address@domain.invalid

–  
Gerardo S.  
“Between individuals, as between nations, respect for the rights of  
others is peace” - Don Benito Juárez

> **[Santana's Tech Notes](http://santanatechnotes.blogspot.com/)**
>
> Small notes about technical related stuff I do, mainly OpenBSD and Ruby
