# How can I add a new fct to the class Hash

**URL:** <https://www.ruby-forum.com/t/how-can-i-add-a-new-fct-to-the-class-hash/79510>\
**Category:** Ruby\
**Created:** [March 10, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/how-can-i-add-a-new-fct-to-the-class-hash/79510 "2006-03-10T17:07:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [March 10, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/how-can-i-add-a-new-fct-to-the-class-hash/79510/1 "2006-03-10T17:07:15Z")

</div>

Hi,

We use a lot of “hash” in our program and we want to  
add a new function to the class, does someone know how  
to do this???

Thanks you very much

sayoyo

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [March 10, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/how-can-i-add-a-new-fct-to-the-class-hash/79510/2 "2006-03-10T17:13:07Z")

</div>

Hi –

On Sat, 11 Mar 2006, removed\_email\_address@domain.invalid wrote:

> Hi,
> 
> We use a lot of “hash” in our program and we want to  
> add a new function to the class, does someone know how  
> to do this???

class Hash  
def new\_method  
#…  
end  
end

Keep in mind, though, that it’s risky to change core classes unless  
you’re certain that the code you’re writing won’t be mingled with  
other code.

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [March 10, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/how-can-i-add-a-new-fct-to-the-class-hash/79510/3 "2006-03-10T17:19:26Z")

</div>

class Hash  
def new\_meth  
puts ‘do stuff here…’  
end  
end

h = {}  
h.new\_meth  
=\>
