# Subclassing, using an alternativ constructor

**URL:** <https://www.ruby-forum.com/t/subclassing-using-an-alternativ-constructor/145737>\
**Category:** Ruby\
**Created:** [August 13, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/subclassing-using-an-alternativ-constructor/145737 "2008-08-13T14:05:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [August 13, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/subclassing-using-an-alternativ-constructor/145737/1 "2008-08-13T14:05:29Z")

</div>

Hi list,

I want to create a subclass of GConf::Client, but using  
GConf::Client.new is deprecated, GConf::Client.default should be used  
instead.  
If I call super in ‘initialize’ it of course calls the ‘new’  
constructor of the superclass, how can I call ‘default’ instead?

```
#!/usr/bin/env ruby

require 'gconf2'

class Preferences < GConf::Client

    def initialize
        super
    end

end

Preferences.new

```

Which results in: warning: GConf::Client.new is deprecated. Use  
GConf::Client.default instead.

Regards

Chris

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [August 13, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/subclassing-using-an-alternativ-constructor/145737/2 "2008-08-13T16:58:05Z")

</div>

On Wed, Aug 13, 2008 at 7:02 AM, Christian K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi list,
> 
> I want to create a subclass of GConf::Client, but using  
> GConf::Client.new is deprecated, GConf::Client.default should be used  
> instead.  
> If I call super in ‘initialize’ it of course calls the ‘new’  
> constructor of the superclass, how can I call ‘default’ instead?

Why not follow the example of the superclass and use ‘default’ instead  
of ‘new’ for your subclass as well?

-Michael

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [August 13, 2008, 10:03pm UTC](https://www.ruby-forum.com/t/subclassing-using-an-alternativ-constructor/145737/3 "2008-08-13T22:03:38Z")

</div>

2008/8/13 Christian K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I want to create a subclass of GConf::Client, but using  
> GConf::Client.new is deprecated, GConf::Client.default should be used  
> instead.

Christian, Class#new calls Object#initialize, not the other way round.  
If you want the subclass’ #new method to call the superclass’ #default  
method, you should do it like this:

class Preferences \< GConf::Client  
def self.new  
default  
end  
end

Regards,  
Pit
