From: Sam Roberts <sroberts@bycast.com>
Date: August 31, 2006 11:44:20 PM GMT+02:00
To: Markus Gaelli <gaelli@emergent.de>
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"
=> "hi"
irb(main):002:0> class String; def this(opt) puts(self+opt) end end
=> nil
irb(main):003:0> s.this(" that")
hi that
=> nil
irb(main):004:0> "bye".this(" that")
bye that
=> nilCheers,
Sam
ยทยทยท
Begin forwarded message:
On Fri, Sep 01, 2006 at 06:08:11AM +0900, Markus Gaelli wrote: