Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > warning: method redefined

Reply
Thread Tools

warning: method redefined

 
 
Iain Barnett
Guest
Posts: n/a
 
      08-24-2010
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=

 
Reply With Quote
 
 
 
 
Iain Barnett
Guest
Posts: n/a
 
      08-24-2010

On 24 Aug 2010, at 19:49, Iain Barnett wrote:

> 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?
>=20


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=

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      08-26-2010
Iain Barnett wrote:
> 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Iain Barnett
Guest
Posts: n/a
 
      08-26-2010

On 26 Aug 2010, at 14:57, Brian Candler wrote:

> Iain Barnett wrote:
>> It turns out one of the other files in the library also had require=20=


>> 'file/fo'o etc, so some files were required twice. What I don't=20
>> understand is why this would generate warnings, as my understanding =

is=20
>> that require can be called as multiple times but will only load the=20=


>> files once. Is this incorrect?

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a method of a base class that is redefined in a extendedclass robbie.desutter@gmail.com Java 5 12-04-2007 09:11 AM
Array.sort when it's items are String inheritors with redefined <=> works like if not redefined MiG Ruby 8 10-19-2005 03:48 PM
Finding out if a method is already redefined Michael Schuerig Ruby 2 09-18-2005 01:23 PM
Removing "warning: method redefined" Brian Takita Ruby 4 07-08-2005 04:36 PM
delegate.rb:110: warning: method redefined; discarding old __getobj__ Simon Strandgaard Ruby 0 02-23-2004 06:28 PM



Advertisments