Subclassing, using an alternativ constructor

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

On Wed, Aug 13, 2008 at 7:02 AM, Christian K. [email protected] 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

2008/8/13 Christian K. [email protected]:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs