How can I add a new fct to the class Hash


#1

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


#2

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)

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


#3

class Hash
def new_meth
puts ‘do stuff here…’
end
end

h = {}
h.new_meth
=>