Warning: redefining Object#initialize may cause infinite loop

Is there anyway I can supress this warning?

I tried setting $VERBOSE = FALSE before then
back to TRUE after my bit of code but nothing...

I seem to unconciously miscode initialize to initialise.
every. single. time.

so I did

class Object
    def initialize
  initialise
    end
end

while it works, it throws the hissy error
warning: redefining Object#initialize may cause infinite loop

I just want to supress the error in my code.

-- Dark Fiber --
[FAQ] Write Your Own Operating System
    http://www.mega-tokyo.com/osfaq2
3x3 Eyes Fanfiction Archive
    http://www.mega-tokyo.com/pai

Stu wrote:

Is there anyway I can supress this warning?

I tried setting $VERBOSE = FALSE before then
back to TRUE after my bit of code but nothing...

I seem to unconciously miscode initialize to initialise.
every. single. time.

so I did

class Object
    def initialize
  initialise
    end
end

while it works, it throws the hissy error
warning: redefining Object#initialize may cause infinite loop

I just want to supress the error in my code.

Hmm, how about an alias instead?

I suppose this would work:

   class Object
     alias initialise initialize
   end

Haven't tried it, though...

Hal

Unless I'm minsreading what you want to do, wouldn't it be

def initialise
    initialize
end

The way you're doing it now, you're re-defining the "real" initialize method to redirect to the fake one.

- B

Stu wrote:

···

Is there anyway I can supress this warning?

I tried setting $VERBOSE = FALSE before then
back to TRUE after my bit of code but nothing...

I seem to unconciously miscode initialize to initialise.
every. single. time.

so I did

class Object
   def initialize
initialise
   end
end

while it works, it throws the hissy error
warning: redefining Object#initialize may cause infinite loop

I just want to supress the error in my code.

-- Dark Fiber --
[FAQ] Write Your Own Operating System
   http://www.mega-tokyo.com/osfaq2
3x3 Eyes Fanfiction Archive
   http://www.mega-tokyo.com/pai

Hi,

···

In message "Re: warning: redefining Object#initialize may cause infinite loop" on Fri, 12 Nov 2004 09:23:29 +0900, Stu <ceaser@rome.net> writes:

so I did

class Object
   def initialize
initialise
   end
end

while it works, it throws the hissy error
warning: redefining Object#initialize may cause infinite loop

I just want to supress the error in my code.

At the risk of what warning message says?
Try "$VERBOSE = nil" if you're sure.

              matz.

Redefine Object.new, not Object#initialize

# untested code below, but I think it is OK.

class Object
  def self.new(*args, &block)
    obj = allocate

    if obj.respond_to? :initialise then
      obj.initialise
    else
      obj.initialize
    end
    
    return obj
  end
end

···

On Nov 11, 2004, at 4:23 PM, Stu wrote:

Is there anyway I can supress this warning?

I tried setting $VERBOSE = FALSE before then
back to TRUE after my bit of code but nothing...

I seem to unconciously miscode initialize to initialise.
every. single. time.

so I did

class Object
    def initialize
  initialise
    end
end

I think his problem is he's writing things like:
class SomeNewClass
         def initialise
               ....
         end
end

which is why he wants Object#initialize to call initialise

···

On Fri, 12 Nov 2004 10:11:37 +0900, Brian Palmer <brian@pocketmartiansoftware.com> wrote:

Unless I'm minsreading what you want to do, wouldn't it be

def initialise
    initialize
end

The way you're doing it now, you're re-defining the "real" initialize
method to redirect to the fake one.

- B

Stu wrote:

>Is there anyway I can supress this warning?
>
>I tried setting $VERBOSE = FALSE before then
>back to TRUE after my bit of code but nothing...
>
>I seem to unconciously miscode initialize to initialise.
>every. single. time.
>
>so I did
>
>class Object
> def initialize
> initialise
> end
>end
>
>while it works, it throws the hissy error
>warning: redefining Object#initialize may cause infinite loop
>
>I just want to supress the error in my code.
>
>
>
>-- Dark Fiber --
>[FAQ] Write Your Own Operating System
> http://www.mega-tokyo.com/osfaq2
>3x3 Eyes Fanfiction Archive
> http://www.mega-tokyo.com/pai
>
>
>
>
>
>

Hi,

<snip>

At the risk of what warning message says?
Try "$VERBOSE = nil" if you're sure.

                                                        matz.

This makes me want to ask (after playing with $VERBOSE) why $VERBOSE =
false is different than $VERBOSE = nil. Not that I would presume to
contest Matz, (thank you for Ruby oh so much) but doesn't this break
the whole false and nil are false concept? Would it be worse if it
were a numeric scale (like -W)?

···

On Fri, 12 Nov 2004 10:52:21 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

>
> Is there anyway I can supress this warning?
>
> I tried setting $VERBOSE = FALSE before then
> back to TRUE after my bit of code but nothing...
>
> I seem to unconciously miscode initialize to initialise.
> every. single. time.
>
> so I did
>
> class Object
> def initialize
> initialise
> end
> end

Redefine Object.new, not Object#initialize

# untested code below, but I think it is OK.

class Object
        def self.new(*args, &block)
                obj = allocate

                if obj.respond_to? :initialise then
                        obj.initialise
                else
                        obj.initialize
                end

                return obj
        end
end

That would do it. But it still seems better to learn the correct
syntax. Perhaps:

  class Class
    alias oldnew new
    def new(*args,&block)
      warn "#initialise is defined, perhaps you meant initialize?" if
instance_methods.include? "initialise"
      oldnew(*args,&block)
    end
  end

This way it doesn't change the syntax, but you get a nice warning so
you can correct the mistake.

cheers,
Mark

···

On Sat, 13 Nov 2004 04:41:23 +0900, Eric Hodel <drbrain@segment7.net> wrote:

On Nov 11, 2004, at 4:23 PM, Stu wrote:

(IMHO) I've always wished it were just #init.

T.

···

On Thursday 11 November 2004 08:30 pm, Logan Capaldo wrote:

I think his problem is he's writing things like:
class SomeNewClass
         def initialise
               ....
         end
end

which is why he wants Object#initialize to call initialise

Hi,

···

In message "Re: warning: redefining Object#initialize may cause infinite loop" on Fri, 12 Nov 2004 11:04:57 +0900, Logan Capaldo <logancapaldo@gmail.com> writes:

This makes me want to ask (after playing with $VERBOSE) why $VERBOSE =
false is different than $VERBOSE = nil. Not that I would presume to
contest Matz, (thank you for Ruby oh so much) but doesn't this break
the whole false and nil are false concept? Would it be worse if it
were a numeric scale (like -W)?

a1) No, even though false and nil are false values, they are not same,
    not interchangeable.

a2) they are not numeric scale just for historical reason. So it will
    not be worse except for compatibility.

              matz.

trans. (T. Onoma) wrote:

> I think his problem is he's writing things like:
> class SomeNewClass
> def initialise
> ....
> end
> end
>
> which is why he wants Object#initialize to call initialise

(IMHO) I've always wished it were just #init.

I can live with initialize.

But I'm now wondering if it might be acceptable to allow *either*
of these.

Might be problematic, though. It's not like an alias, but more
like the reverse of one.

What if someone defined #initialize AND #initialise? We'd want to
detect that (and give an error, I guess). And what if one existed,
and the other was later defined dynamically? Etc., etc.?

All in all, I guess things are best the way they are. This may be
a thought process that Matz went through in 1993, and much faster
than I just did.

Hal

···

On Thursday 11 November 2004 08:30 pm, Logan Capaldo wrote:

trans. (T. Onoma) ha scritto:

(IMHO) I've always wished it were just #init.

T.

me too, then I realized that :init is a name that is better to leave to people for their own intents, just like :id .