warning: redefining Object#initialize may cause infinite loop

S

Stu

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
 
H

Hal Fulton

Stu said:
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
 
B

Brian Palmer

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
 
L

Logan Capaldo

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


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



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
 
T

trans. (T. Onoma)

| 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.

T.
 
H

Hal Fulton

trans. (T. Onoma) said:
| 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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: warning: redefining Object#initialize may cause infinite loop"

|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.
 
L

Logan Capaldo

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)?
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: warning: redefining Object#initialize may cause infinite loop"

|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.
 
G

gabriele renzi

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 .
 
E

Eric Hodel

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
 
M

Mark Hubbart

Hi,


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top