# \[Q\] How would you do method extensions (sometimes called class extensions) in Ruby?

**URL:** <https://rubytalk.org/t/q-how-would-you-do-method-extensions-sometimes-called-class-extensions-in-ruby/30540>\
**Category:** ruby-talk\
**Created:** [31 August 2006 23:17 UTC](https://rubytalk.org/t/q-how-would-you-do-method-extensions-sometimes-called-class-extensions-in-ruby/30540 "2006-08-31T23:17:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markus\_Gaelli](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Markus\_Gaelli](https://rubytalk.org/u/Markus_Gaelli)\
**Post date:** [31 August 2006 23:17 UTC](https://rubytalk.org/t/q-how-would-you-do-method-extensions-sometimes-called-class-extensions-in-ruby/30540/1 "2006-08-31T23:17:40Z")

</div>

> From: Markus Gaelli \<gaelli@emergent.de\>  
> Date: September 1, 2006 1:04:50 AM GMT+02:00  
> To: ruby-core@ruby-lang.org  
> Subject: Re: [Q] How would you do method extensions (sometimes called class extensions) in Ruby?
> 
> Sam and Nicolas,
> 
> thanks for your fast answers and pointers.  
> Guess I have to subscribe to another list - which is a good thing!  
> - Just wanted to be sure... 😉  
> (I therefore forward another mail which just happened to arrive in this moment in my squeak mailbox)
> 
> > > 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  
> > =\> nil
> 
> I was reading (skimming) the Ruby book of Thomas and Hunt but could not find this. Thanks a lot!  
> I appreciate Ruby to be able to extend any class with any methods.
> 
> Cheers,
> 
> Markus
> 
> p.s. Funny that you have "reply" set to the person who answered and not to the list, different than in Squeak and Squeakland...

> **···**
>
> Begin forwarded message:
> 
> > On Aug 31, 2006, at 11:44 PM, Sam Roberts wrote:
> > 
> > > On Fri, Sep 01, 2006 at 06:08:11AM +0900, Markus Gaelli wrote:
