From: Sam Roberts <firstname.lastname@example.org>
Date: August 31, 2006 11:44:20 PM GMT+02:00
To: Markus Gaelli <email@example.com>
Subject: Re: [Q] How would you do method extensions (sometimes called class extensions) in Ruby?
I am aware of Singleton Methods, but as they can extend instances,
(how) can I extend classes without changing their original class
definition in Ruby?
This is probably best posted to ruby-talk, not ruby-core, folks would
likely be quite interested.
classes are "open" in ruby, you can add methods as you wish.
irb(main):001:0> s = "hi"
irb(main):002:0> class String; def this(opt) puts(self+opt) end end
irb(main):003:0> s.this(" that")
irb(main):004:0> "bye".this(" that")
Begin forwarded message:
On Fri, Sep 01, 2006 at 06:08:11AM +0900, Markus Gaelli wrote: