Forum: Ruby how can I add a new fct to the class Hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A9b164143d290c49d56504e1f092689f?d=identicon&s=25 sayoyo S. (sayoyo)
on 2006-03-10 17:07
(Received via mailing list)
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
unknown (Guest)
on 2006-03-10 17:13
(Received via mailing list)
Hi --

On Sat, 11 Mar 2006, sayoyo@yahoo.com 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 (dblack@wobblini.net)
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
Mark Van Holstyn (Guest)
on 2006-03-10 17:19
(Received via mailing list)
class Hash
  def new_meth
    puts 'do stuff here...'
  end
end

h = {}
h.new_meth
  =>
This topic is locked and can not be replied to.