[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

warning: redefining Object#initialize may cause infinite loop

Stu

11/12/2004 12:22:00 AM


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....
3x3 Eyes Fanfiction Archive
http://www.mega-tok...
17 Answers

Hal E. Fulton

11/12/2004 1:06:00 AM

0

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



Brian Palmer

11/12/2004 1:12:00 AM

0

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....
>3x3 Eyes Fanfiction Archive
> http://www.mega-tok...
>
>
>
>
>
>


Logan Capaldo

11/12/2004 1:30:00 AM

0

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....
> >3x3 Eyes Fanfiction Archive
> > http://www.mega-tok...
> >
> >
> >
> >
> >
> >
>
>


T. Onoma

11/12/2004 1:46:00 AM

0

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

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

T.


Hal E. Fulton

11/12/2004 1:51:00 AM

0

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




Yukihiro Matsumoto

11/12/2004 1:52:00 AM

0

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.


Logan Capaldo

11/12/2004 2:05:00 AM

0

On Fri, 12 Nov 2004 10:52:21 +0900, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote:
> 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)?


Yukihiro Matsumoto

11/12/2004 2:14:00 AM

0

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.


gabriele renzi

11/12/2004 10:30:00 AM

0

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 .

Eric Hodel

11/12/2004 7:41:00 PM

0

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

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