Hi,


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