warning: method redefined

I

Iain Barnett

Hi,

Any idea how to track down `warning: method redefined` errors? Is there =
a way to force errors to appear with irb when I load individual files?

AFAICS I've not redefined anything. It's all my own, very small library. =
This all started when I installed 1.9.2, which I'm beginning to regret =
for the amount of consternation it's causing me.


Regards,
Iain=
 
I

Iain Barnett

Hi,
=20
Any idea how to track down `warning: method redefined` errors? Is =
there a way to force errors to appear with irb when I load individual =
files?

It turns out one of the other files in the library also had require =
'file/fo'o etc, so some files were required twice. What I don't =
understand is why this would generate warnings, as my understanding is =
that require can be called as multiple times but will only load the =
files once. Is this incorrect?

Regards,
Iain=
 
B

Brian Candler

Iain said:
It turns out one of the other files in the library also had require
'file/fo'o etc, so some files were required twice. What I don't
understand is why this would generate warnings, as my understanding is
that require can be called as multiple times but will only load the
files once. Is this incorrect?

It can happen if you require them in different ways, e.g.

require 'file/fo'
require './file/fo'
require '../lib/file/fo'
require File.join(File.dirname(__FILE__), 'fo')

If that's what's happening, the solution is to be consistent with your
require statements, and if necessary set up $: (aka $LOAD_PATH) suitably
at the start of your program.
 
I

Iain Barnett

=20
It can happen if you require them in different ways, e.g.
=20
require 'file/fo'
require './file/fo'
require '../lib/file/fo'
require File.join(File.dirname(__FILE__), 'fo')
=20
If that's what's happening, the solution is to be consistent with your=20=
require statements, and if necessary set up $: (aka $LOAD_PATH) = suitably=20
at the start of your program.
--=20
Posted via http://www.ruby-forum.com/.

Ah, I see. Yes, a part of the code was dynamically calling require, and =
the offending statements were static.

One more gotcha in the bag! Thanks. Nice thing about all the "gotchas" =
I've found in Ruby so far is that they may be frustrating at the time, =
but they don't kill the fun of the language.

Regards,
Iain=
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top